So I have a weird problem when trying to linecast between two gameobjects. I’m making a layer mask which should make the linecast avoid the colliders of both the linecast sender and linecast receiver, however the linecast always ends up hitting the collider of the receiver object.
var mask : int = ~(1 << gameObject.layer) | ~(1 << target.gameObject.layer); // Ignore just my layer and my target layer, check against everything else
var lineHit : RaycastHit;
if(!Physics.Linecast(transform.position, target.position, lineHit, mask)){
// No colliders hit, target is visible, do stuff!
}
These lines of code always hit the target’s collider. What am I doing wrong ?
If I’m not mistaken, the 4th parameter in this function is used for the range of the cast, not the mask. Try adding another variable between lineHit and mask.
Thanks for replying! Maybe you got confused because of the Raycast function. The Linecast function casts a ray from point A to point B no matter how far they are from each other. There is no range parameter.
Here, check out the manual: http://docs.unity3d.com/Documentation/ScriptReference/Physics.Linecast.html
I’m using the second constructor which has the parameters exactly as I’ve done them (start, end, hitinfo, layermask)