- Home /
Question by
$$anonymous$$ · Jan 08, 2018 at 06:37 PM ·
2dairaycasting2d-physicslinecast
Linecast is always blocked.
I'm trying to detect if there is any 2d collider obstacle (such as wall) between the player and the enemy.
I'm trying to use this script
if (Physics2D.Linecast (new Vector2 (transform.position.x, transform.position.y), new Vector2 (target.position.x, target.position.y)))
{
Debug.Log("There is something in the way");
}
I'm not sure why it's not working. Even if there is no 2d collider between the player and the enemy, the script still outputs to the console.
Comment
Answer by Jinnie26 · Jan 09, 2018 at 02:42 PM
I don't know if it works for your problem but I use this for raycast so that the raycast wont hit the Collider on the same gameobject
Physics2D.queriesStartInColliders = false;
Answer by adriant · Jan 09, 2018 at 02:34 PM
That Physics2D.Linecast()
call always returns a RaycastHit2D struct, isn't it?