Hello
I have a piece of code that sends out a ray with a layer mask but its not hitting the collider i am aiming for and do not know why.
My method that does this is:
public LayerMask layerMaskFloor;
public Vector3? WorldPosition()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMaskFloor))
{
Debug.Log(hit.point);
return hit.point;
}
Debug.Log("NULL");
return null;
}
I keep getting NULL as a result.
My camera has a physics raycaster component attached with event’s set to “everything” and my mouse is definitely above the outline of my box collider, yet for some reason, my if statement keeps returning false.
Can also confirm my layer mask variable is set in the inspector correctly.
What else could i test to find the problem here?