Grounded and pressing "jump" not working?
I'm trying to make my character jump. I want to do this by checking that the character controller is grounded, and that the jump button has been pressed. Individually, these work correctly if(controller.isGrounded)
and if(Jump button pressed)
), but together they don't.` Why not? If they are both true on their own, why aren't they true one after the other?
EDIT: I've figured out what the main problem was: it was the fact that my character wasn't moving along his yVelocity at all so I guess it couldn't tell if it was grounded. However a new problem has arisen. Even when the method itself is invoked (that is, when the jump button is pressed and the character is on the ground) the Y Velocity doesn't change. So the method is called but for some reason it won't make the character jump? I'd say it's about 60% of the time the character jumps and 40% it just ignores it.
Answer by Major · Jul 03, 2017 at 03:59 PM
In my experience with the CC, it has poor ground detection. The best way I can put it is that it "flickers" true/false very quickly. Without seeing more code and understanding exactly how everything works, I would say that you might need to set a vertical velocity when grounded (something small like Time.deltaTime has worked fine in my experiments), and calling CC.Move () to apply said velocity. I hope that helps, again it's hard to address the question without seeing application.
That's unfortunate. The strange thing is that it was working when I first implemented the jump mechanic; it would call the Jump() method every frame and check the two if statements one after the other, but now it seems to be ignoring them.
Currently my character's vertical velocity is set to -gravity if grounded and if not is set to -= gravity. Do you think this might be casing an issue? Again it seemed to work fine before.
EDIT: I've figured out what the main problem was: it was the fact that my character wasn't moving along his yVelocity at all so I guess it couldn't tell if it was grounded. However a new problem has arisen. Even when the method itself is invoked (that is, when the jump button is pressed and the character is on the ground) the Y Velocity doesn't change. So the method is called but for some reason it won't make the character jump?
I really wish I got emails for these things...
I'm sorry I didn't see this. You should probably check to make sure that the y-velocity is being set in a continuous function like update or fixed update.
Your answer
Follow this Question
Related Questions
Using Velocity breaks my jumping 0 Answers
Double Jump using character controller 0 Answers
Problem with Jump script 1 Answer
Jump logic issues 0 Answers