hey - not sure if I’m doing this wrong but I cannot get a raycast to work with only a certain layermask
this my code
if (Physics.Raycast(ray, out rayInfo, 1<<11)) { // hit object with mask 11 }
Though it will still hit everything! I have set the Layers on the objects that I want to test against… and I would have thought that even if I didn’t, then at least the raycast would return nothing? (nothing on that layer)
So why would that code above still return hits from anything and everything that has a collider on it?
Thanks!
Hm there doesn’t seem to be a Raycast function that matches those parameters. I think you might be passing your layermask as the distance instead… Unity - Scripting API: Physics.Raycast
I tend to avoid using bit shifting when working with layermasks though, and handle it via inspector properties instead.
This is in js, but you can get the idea!
var myMask : LayerMask;
if( Physics.Raycast(ray, rayHit, rayDistance, myMask) )
hey Aniani - yep it was a facepalm moment where I wasn’t looking at what I was doing! …and I’ve setup the layermasks now to be inspector members!
thanks!