In my current project all enemies cast a linecast towards the player, but even when there are walls between them the raycasthit2d.transform always returns the player transform anyway, why is this happening?
RaycastHit2D ray = Physics2D.Linecast(transform.position, player.transform.position, 9);
print(ray.collider);
if (ray.transform == player.transform)
{
print("in sight");
}
also: 9 is the layermask of the enemy so it doesn’t return itself, also just found out that when you set the layermask to wall it always returns null