- Home /
Alternates to Linecast for a gameobject without collider.
Hi,
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?
Why don't you want a collider on the player?
What is the purpose of the Linecast? Is is test whether the enemies can see the player, or something else?
Answer by Andres Barrera · Aug 07, 2014 at 04:38 PM
Hi,
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: http://docs.unity3d.com/Manual/LayerBasedCollision.html
Then you can set the Physics2D.Linecast method to check only for the player's layer, with the "layerMask" parameter: http://docs.unity3d.com/ScriptReference/Physics2D.Linecast.html
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.
Your answer