Detecting floor collision

Hello, I am trying to detect when a player hit the floor and when he leaves it to play the right animation.
The player is a dynamic rigid body (a capsule). The floor is static and can have any shape.
So, I have tried two methods.
First, using the collisionstart event, but I need to make sure that the collision is on the lower side of the capsule (the player foot). Actually, this worked with normal collision shapes but not with mesh collision because the contact points are not always exact. (I have no idea why the y of the contact.localPoint sometimes is “much” superior than the y of the bottom of the player even though the floor is under his foot). Anyway I don’t like this idea.
Second, I tried using raycasts to check if there is a floor under the player but this is not perfect because the raycast is a thin line, and the player could be sometimes be at the edge of the floor and the raycast won’t hit the floor. (I even tried with 5 raycasts one in the middle and 4 in the sides, better but still not the best, and I’m not ok with iterating each frame.)
So, what is the best way to do this? I am thinking of a collision volume under the player but it won’t trigger with static bodies :c

One way I can think to get around this is to use a capsule and if you get a contact point, check that it is lower or the same as the base position of the capsule. If it is, the player is on the ‘floor’

1 Like

Can you try using a different type of collision(eg a box)? Another way you can do this is to have an entity which is a parent of the player. The entity could then be the rigidbody and the player would be the child of the entity. You can then attach all of the rigidbody scripts to the parent entity.