I am trying to get a raycast to ignore a layer, but am having problems, I’m not entirely sure how to get layer 8 in this instance to be ignored.
void ShootMissile()
{
LayerMask layerMask = ~1 << 8;
RaycastHit hitInfo = new RaycastHit();
bool hit = Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hitInfo);
if (hit)
{
//My amazing function
}
}
Am I declaring the layer mask correctly on Line 3?
On Line 5, where I think that I should add the LayerMask I don’t really want to add the condition of Max Distance. What do you suggest I do, add some arbitrary number into Max Distance? I did try the following -
LayerMask layerMask = ~1 << 8;
RaycastHit hitInfo = new RaycastHit();
bool hit = Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hitInfo, 1000f, layerMask);
Which did not resolve my problem.
I’m happy to provide more information if needed, thanks.
Thanks @LaneFox , I have now changed my code to - bool hit = Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hitInfo, 50, Mask);
And have declared what the Mask is in the Inspector. Now when the ray is shot, it doesn’t go past if(hit) {}. Why isn’t it getting past the if statement any more? Regardless of where I am trying to hit (on the mask, or not), it isn’t hitting anything.