Hello Unity community,
I’ m working on my first Unity project and I can’t solve the following issue: physics raycast is not working on a mesh collider. The raycast is between player and ground.
- Player has a rigidbody attached and a sphere collider.
- Ground has a rigidbody and a non-convex mesh collider.
- Collision works perfectly but raycast detects nothing.
- Maybe my “ignore raycast” configuration is wrong, I’m new to this.

I’ve been looking for hours and can’t find the solution.
Thanks in advance,
Pablo
EDIT: Just realize there’s a special place for answers, going to post there, sorry.
The forums are just as good a place to ask for help as the answer page =)
Have you set the “layers” on your objects? Unity will not automatically know what object the “Player” is, so you have to select the Player GameObject and set the Layer to “Player” in the upper-right of the inspector.
On colliders, there’s a checkbox for “IsTrigger”. Physics raycasts usually don’t hit triggers unless you tell it to with the “queryTriggerInteraction” parameter in the raycast function call.
Thanks for the response,
Both gameobjects have their corresponding layers and none of the colliders have “isTrigger” activated. After hours of trying to solve this I was thinking the problem has something to do with Tiled2Unity mesh. In order for the Player to collide with the mesh imported from Tiled, I have to use a sphere collider becase 2D colliders won’t work. The collision works, however raycast never works. However, when I add a Box collider to the tilemap, raycast works inmediately. Could it be because the mesh has no Z size? I’m out of ideas.
Ahh, your problem is that Physics.Raycast() only hits 3D colliders. To hit 2D colliders, use a Physics2D.Raycast()