This is quite odd, I’ve used layer masks before with no problems, so not sure what is happening. I’m trying to use a simple layer mask.
int layerMask = 1 << 12;
layerMask = ~layerMask;
Ray ray camera.ScreenPointToRay(new Vector3(x, y, 0));
RaycastHit hit;
if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask))
{
Debug.Log("Hit: " + hit.transform.name + " Layer: " + hit.transform.layer);
}
So I want to hit all layers except layer 12, but no matter what I do, it always hits it. I even tried taking out layerMask = ~layerMask (which wouldn’t make any sense) and of course it still hits it. Both times it prints out Layer 12.
Any ideas?