Raycast hit ignores everything except for the terrain

Hello! I just started learning unity and I’m trying to detect when the player looks at something using raycast hit. However, the issue I’m facing is that every object basically gets ignored by it except for one plane that the character’s standing on. Here are some code snippets:

if (Physics.Raycast(cameraCenter, camera.forward, out hit, 100f, groundMask)) { lookObject = hit.transform.gameObject; print(lookObject); } else { lookObject = null; }

Hey there, the reason you are experiencing this is because at the very end of you sending the raycast, you have put that the only thing that effects your raycast is anything with the layer of ground which you assign in the Unity editor. If you would like your raycast to be effected by everything, then you can just take off the last part of the raycast line, or the part where it says “groundMask”. Then, everything with a collider will now effect the raycast. I hope this helped out.