Alternates to Linecast for a gameobject without collider.


My player doesn’t have an enabled collider and I use rays to detect collision but my enemies used to use Physics2D.Linecast to detect the player and now they can’t, since it doesn’t have an active collider anymore.

Is there any alternative to achieve the same effect without Linecast?


Will it work for you if you set a collider on the player, but set its collision layer to one that won’t bother you with unwanted collisions?
Check this: Unity - Manual: Layer-based collision detection

Then you can set the Physics2D.Linecast method to check only for the player’s layer, with the “layerMask” parameter: Unity - Scripting API: Physics2D.Linecast

If you want to avoid colliders completely, you can check the distance between the enemies and the player using simple vector math, but this won’t take into account possible obstacles between them.

Hope that helps.