Ok, this is seemingly an extremely simple question. Whenever I apply Y movement (gravity) to a charactercontroller, the expected behavior happens and the object falls down until it hits the ground. The issue is when I stop applying gravity, the CharacterController constantly fluctuates between isGrounded = false and isGroudned = true. I've stripped down literally everything except for a few lines of code to test with:
In the code above, once the charactercontroller falls to the ground, isGrounded keeps returning true as expected. When I try this code...
...the controller fluctuates isGrounded values every few frames.
How do I keep the controller grounded without having to constantly apply gravity? Once it's grounded, shouldn't it stay grounded until I apply movement in the opposite direction? Thanks.
asked Oct 16, 2012 at 04:32 AM
I suspect that isGrounded is set by collisions in the bottom side of the CharacterController. If you wait the CC (CharacterController) to become grounded, then remove the gravity and move it horizontally, isGrounded becomes false. In your code, gravity is applied as a downwards velocity whenever the isGrounded is false; when it becomes true, you cancel the vertical velocity, what makes isGrounded turn to false - gravity is applied again, isGrounded becomes true, gravity is suspended, and so on, creating a loop that flips isGrounded true/false continuously. Why do you want to suspend gravity? Usually, the gravity is continuously applied in order to keep the CC grounded, and there's nothing wrong with this.
answered Oct 16, 2012 at 12:42 PM