Problems with a grounded check for the player character
Reported by: Eldar Bertsel
October 6, 2023
THE PROBLEM
I ran into an issue where the grounded check for the player controller wasn't being consistent. I was using CharacterController built in isGrounded check. But the problem with it is that it checks whether CharacterController was grounded in the last frame. Because of that if the CharacterController is initially at the ground level the ground check would say false because last frame the CharacterController wasn't moved therefore it can't say whether playerCharacter is grounded or not so it will use the default value which is false. I found a way how to go about it by adding a negative vertical velocity that is enough for the IsGrounded to say true because playerCharacter moved a little vertically and the ground is right below us. I thought that would solve the issue but now I got another issue. Indeed, isGrounded was working but it was very inconsistent. It would turn on and off all the time and that was a problem because my character can rotate only when the playerCharacter is grounded. Because of that the rotation was cutting all the time which looked like we are losing frames.
THE SOLUTION
The solution I came up with, was to create a sphere right where the player's feet are, which will check for the collision, telling, whether the playerCharacter is grounded or not. Using this approach I would also have to create my own isGrounded variable that I will turn on and off depending on the sphere collision check results. I also connected that variable to the animator so that I can use it to change the animations to falling if the isGrounded is false and action animations if isGrounded is true. Also, I have a time variable that count the time since isGrounded was false last time. I use that for the animations too. If isGrounded is false for more that 1 second then the playerCharacter starts falling, if for less that then it just keep playing the previous animation. This is very useful when implementing the jump. I think this is a good way of doing it. The only downside is if the sphere's radius is too big then it will look like the player is floating rather than standing directly on the ground. To fix that I adjusted the CharacterController collider and the sphere position. This way the character looks like it is standing on the ground while having both colliders present
Get Psyche
Psyche
Welcome to your next great souls-like adventure!
Status | In development |
Author | Sad Ogre Studios |
Genre | Role Playing, Adventure |
Tags | Atmospheric, Fantasy, Indie, mind-bending, psyche, Sci-fi, Singleplayer, Souls-like, Third Person |
More posts
- Problem: Harder Isn't Always More FunDec 14, 2023
- How to make the controller feel more responsiveDec 14, 2023
- ModelMayhem: A Programmer's TaleDec 08, 2023
- Problem: Face Your FearsDec 03, 2023
- Time to show our real main characterDec 01, 2023
- Problems: melee combat system is too boringNov 24, 2023
- Problem: Frames Win Games?Nov 17, 2023
- Problem with camera transitionNov 16, 2023
- Combo Attack systemNov 11, 2023
- Problems with code reusabilityNov 03, 2023
Leave a comment
Log in with itch.io to leave a comment.