- Home /
How reliable are isGrounded checks?
Do they sometimes randomly trigger off when the player moves?
How does the standard asset "CharacterMotor" apply gravity to the player?
Generally, no. The physics sim is industry-proven. But solving edge cases is part of writing strong controllers, so there's no harm in preparing for that eventually.
Do you mean that is isn't reliable or that it doesn't trigger off? Judging by your "industry-proven", I'm guessing that it is very reliable.
Correct, Unity uses PhysX, one of the (3? 4?) major competing physics engines in the world of realtime graphics. I won't say it never behaves unpredictably, but you can and will learn its weak areas, quirks, and limitations over time. None are insurmountable, if your expectations are reasonable.
Still, much of my code which polls for physics information includes some kind of failsafe for instances where the expected behavior deviates from the norm. This is just a good practice, and you'll come to know when it's necessary. For an isGrounded check, I sort of throw caution to the wind and trust it. I'd say it's exceptionally reliable, especially when used in conjunction with well-designed collision meshes and carefully orchestrated situations.
Answer by flannel40000 · Mar 18, 2015 at 01:07 PM
I found it not to be reliable as I am using a mechicam animation system for a third person shooter and opted towards a character controller for my player rather than a rigidbody after much trial and error with that. I found that my CharacterController.isGrounded did not update after it was marked true as i always start my characters in the air, so I made my own isgrounded application and here is the code for it.
private Vector3 grav;
private CollisionFlags collisionFlags;
private float gravity = 9.8f;
void Update () {
if (IsGrounded()) {
grav.y += -gravity * Time.deltaTime;
cc.Move (grav * Time.deltaTime);
} else {
grav = new Vector3(0,0,0);
}
}
public bool IsGrounded () {
return (CollisionFlags.CollidedBelow) != 0;
}
It is a bit jittery with my character going up and down hills but that requires some smoothing out which I haven't gotten to yet as I made this script today. Bonus points for not using a RayCast system? Hope it helps :)
Your answer
Follow this Question
Related Questions
CharacterController isGrounded toggles value 2 Answers
Adding gravity to character and grounded checks are not working? 0 Answers
controller.Move doesn't stay grounded when walking down slope 3 Answers
Why does my characterController code not apply gravity correctly? 0 Answers
Jumping Stopped Working. 2 Answers