- Home /
IsGrounded working to slow?
Hey Guys,
I am trying to solve this CharacterController isGrounded problem. I have a 2d jump and run, like super mario. After implementing my CharacterController I found that sometimes my player cant jump. Basicly the isGrounded variable works very well. It only happens if my player was in the air/ notGrounded a short time before. For example my character runs down some stairs. The player clearly stops falling on every single stair, but the is grounded variable is never true. If I wait for a millisec the isGrounded becomes true. See the following picture.
If my character walks ( not running) down the exact same stairs the isGrounded variable becomes true on every stair. While bugfixing I tried several things: I used a raycast from the bottom of my player downwards. See the red line on the next screenshot.
The raycast behaves exactly the same like the isGrounded variable. It only „hits“ the stairs when the character walks slow enough.
I don't really understand, why the character stops falling on every stair and clearly collides with the stairs neither the raycast nor the isGrounded variable becomes true? I even tried to add another collider a little bit below the players feet. Same result :( Any ideas how to overcome this problem.
Are you moving your character in Update or FixedUpdate? I would imagine if you moved you character during Update then the physics step would happen the next frame.
Thanks for the answer :) that is correct I am using the update $$anonymous$$ethod to move my character controller. But even then shouldn't the isGrounded variable be true the next frame?
There are quite a few more advantages using Fixed Update ins$$anonymous$$d of Update.. Try switching ,might actually help.
Answer by Benproductions1 · Oct 29, 2013 at 04:21 AM
Hello,
Most likely your problem is a missconception between the meaning of isGrounded
:
IsGrounded
(like your raycast) Is surprisingly not a state that gets evaluated over the time of the Move
, but instead is only relative to the outcome of the Move
.
Lets say your character is standing on the default 1x1x1 cube and call Move
in a downward/forward direction. After the Move
you will end up in the air somewhere off the cube. Obviously you had to collide with the cube for the Move
however, when you check isGrounded
you will see it is false
, as expected.
The same happens when your character starts in the air above the cube. If you have a large vector for Move
, then your character will again end up in a similar position, but on the way down/forward, it must have it the cube. If you check isGrounded
again, it will also be false
.
From this we canconclude, that at any point in time, isGrounded
only checks whether you are currently on the ground, not whether you previously collided with something below you. This usually happens, because your framerate is not high enough for Move
to be accurate enough that you end up on the ground at the same time your jump button is pressed.
As a workaround you have a choice of 2 things:
1. Use the FixedUpdate
loop with a low interval in order to keep movement more accurate (will cause problems making your input work)
2. Write your own CharacterController
and have it remember collisions from below and store them in the isGrounded
state variable (hard work, but definately possible since I've done it before ;) )
Hope this helps,
Benproductions1
Hi,
thx for the answer. I tried the fixedUpdate $$anonymous$$ethod, but this didnt change anything. Still the same weird result. So I am going to write my own charController. Do you have any tutorials or you just developed everything by yourself. If you could post any advice or example code, would be awesome, cause I am still quite new to Unity.
Cheers Pascal
Your answer
Follow this Question
Related Questions
How does unity character controller work? 0 Answers
How to fix the position of a character when grabbing a rope? 1 Answer
Disable collision between mesh collider and character controller 3 Answers
How do I make a Character Controller NOT collide with Rigidbodies? 3 Answers
Building project (web or win) breaks charactercontroller 0 Answers