Linecasting solution, without using layermasks.
Hey guys, this is my first post and i hope to find a solution that will satisfy me.
I have 2 objects (duplicated) who are going to be allies so their layer is set to "ally". this ally has a script with a linecast to detect the other duplicate. They have rigidbodies, and a sphere collider which i want to Linecast starting the center of it.
I tried: inRange = Physics2D.Linecast(sightStart.position,sightEnd.position,1 << LayerMask.NameToLayer("ally"));
While inRange being a a public boolean i noticed that the Linecast is true cause it touches his own collider. My question is.. is there a way to ignore the sphere collider(starting point) so it can detect the collider of its duplicate without having to change their layer?
Thanks in advance! Much love from holland :)
Answer by Shykeas · Feb 28, 2016 at 08:39 PM
Yes. Change the Sphere collider to a layer that doesn't get detected by the ray/linecasts. (In Physic2D, you'll notice layers can be changed of which will collide with which in Edit > Project Settings > Physics2D)