I'm very new to Unity so please excuse my question if this sounds very basic to you.
I'm following various tutorials and I have a small question regarding Physics.Raycast
:
if (Input.GetButton("Fire1")) {
// check ground hit first
RaycastHit hit;
if (Physics.Raycast(ray, out hit, LayerMask.GetMask("Ground"))) {
Debug.Log("[PlayerMotion]: Hit" + hit.collider.name + " " + hit.point);
agent.SetDestination(hit.point);
}
}
Here, even tough I expressively set the layer mask to "Ground"
, I still get a hit with the Player game object itself (the ground hit is working fine). I thought ok maybe I put the "Ground" layer as well on the player by mistake but I checked several times and it's not the case.
I'm attaching a gif so you can see what's the issue exactly
There's an easy by checking the collider.name
but I still find it odd that the Raycast
gives me a false positive with the player hit. Any idea what's going on ?