Player ground detection issue


During this week's dev process, I focused on fixing bugs that can cause either runtime errors or unexpected behaviours. The main issue I faced was the player's ground detection. The problem is that the animation transition is weird if using on collision enter and on collision exit to do the ground detection. It sometimes stucks in the mid air animation, which is not in expectation.

After few tests, I came with a solution, which is to do a capsule overlap detection in fixed update. This capsule overlap will be thiner than the player's capsule collider, and it is going to be shorther as well so that it is completely inside the outer collider, but on the same level as the outer one. Here is what i mean by casting another capsule:

And here is how I do the overlap detection:


In this case the fixed update will keep telling if the player is on ground or not. 

Also another reason why on collision enter and exit won't work is that if there are two ground collider next to each other, and when player walk through the little gap between them, even if there is actually no gap, Unity will immediately tells that the player has left the ground, which is causing a lot troubles.

Author: Zeyuan Song

Posted on 05/02/2024

Get Suits of the Abyss

Leave a comment

Log in with itch.io to leave a comment.