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:
void Update
{
Debug.Log( "is grounded: " + controller.isGrounded );
moveDirection.y -= gravity * Time.deltaTime;
controller.Move( moveDirection * Time.deltaTime );
}
In the code above, once the charactercontroller falls to the ground, isGrounded keeps returning true as expected. When I try this code…
Debug.Log( "is grounded: " + controller.isGrounded );
if( !controller.isGrounded )
{
moveDirection.y -= gravity * Time.deltaTime;
if( moveDirection.y < -maxFallSpeed ) moveDirection.y = -maxFallSpeed;
}
else moveDirection.y = 0;
controller.Move( moveDirection * Time.deltaTime );
…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.