Hi,
Why the following code isn`t working?
Vector2 direction = transform.TransformDirection(Vector2.up);
RaycastHit2D hit = Physics2D.Raycast(transform.position, direction);
if (hit.collider.tag == "Asteroid")
{
print("Object hit");
}
Object is asteroid, the raycast is pointing the right way.
Also I tried
if (hit.collider.gameObject.tag == "Asteroid")
If I write it like this, it completely ignores the other objects.
if (hit.collider != null && hit.collider != parentShip) (ship object that this object is on)
{
print("retarded raycast");
distance = Vector2.Distance(transform.position, hit.point);
}
↧