- Home /
LayerMask sets Raycast.hit to 0
Any idea why when I add a layer mask it is setting my RaycastHit to 0? It's basically going through everything despite the layermask being set to only one layer.
Any help is greatly appreciated. Thank you.
#pragma strict
private var hitInfo : RaycastHit;
private var tr : Transform;
var mask : LayerMask = -1;
function Awake () {
tr = transform;
}
function Update () {
// Cast a ray to find out the end point of the laser
hitInfo = RaycastHit();
Physics.Raycast (tr.position, tr.forward, hitInfo, mask.value);
Debug.Log(hitInfo.distance);
}
function GetHitInfo () : RaycastHit {
return hitInfo;
}
Answer by pajamajama · Jul 20, 2013 at 10:21 PM
I fixed the problem by changing line 23: to Physics.Raycast (tr.position, tr.forward, hitInfo, Mathf.Infinity, mask.value);
I'm blind. Didn't see that extra argument in the docs.
Your answer
Follow this Question
Related Questions
Help Can't find the Correct Parameters 1 Answer
Raycast hit in OnDrawGizmos but not in Update 1 Answer
How to improve the efficiency of ray casting ray detecting collision? 0 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
if ( Physics.Raycast ( ray, out hit, Mathf.Infinity, LayerMask ) ) not working? 2 Answers