- Home /
Whenever I jump and I press the spacebar again midair, the player jumps again as soon as it hits the ground
https://gyazo.com/cdd6fcb7a726e03263fb8dd7884df93f
https://gyazo.com/d73db3cc1d0ed327204dfd8adede3ebd
I'm not sure what I can do to fix it.
Comment
Best Answer
Answer by Sinterklaas · Jun 19, 2021 at 09:29 AM
jumpKeyPressed can only get set to false if the player is grounded.
Instead, write your FixedUpdate function like this:
private void FixedUpdate()
{
if (grounded && jumpKeyPressed)
rb.AddForce(Vector3.up * 5, ForceMode.Impulse);
jumpKeyPressed = false;
}