Basically I have a 4 sided wall, no top, and the player is able to click this wall. There’s an object on the other side of the wall, and I only want the raycast to hit the object on the other side. Using the ignore raycast function works, and while it may, it brings up another problem. My AI is using raycasts to walk around these walls, so using this ignore layer isn’t viable.
I have created a layer mask, and have assigned the wall layer: var ignoreWalls : LayerMask;
I know how to check the wall layer to only cast onto it, but how do I check that layer to not cast onto it, casting through it to other colliders?
if (Physics.Raycast(ray, hit, 100.0, ignoreWalls))
I think you have to assign a value to the LayerMask, and set your gameObject to that layer in the Inspector.
e.g. you might set the object to Layer 10 and name it Walls
Then you’d use LayerMask (1<<10) for the value…
At least that’s what I think… However, I’m using this approach and still having issues with it! (in that the ray isn’t hitting). This is how I have it:
var mask : LayerMask = (1<<10);
if (Input.GetMouseButtonUp (0) Physics.Raycast (ray, hit, 100, mask) hit.transform.name == btn.name){
//Do Stuff
I’ve got it fixed for myself, apparently the test setup I was using earlier had a small issue that’s now resolved. The raycast will go through the wall, providing the wall is of another layer, and the layermask is of the same layer as the object on the other side. I was thinking differently earlier as to how this was working with raycast, oh well, keep trying and you shall learn =).