How will I make my character jump only when it is pressed once

Viewed 27

I have scoured through the internet to find a solution of this but this is the only solution that I could find but it cancels the "yMove += jumpingVelocity * deltatime" as soon as collision is not detected anymore thus it instantly just goes down. If I remove the isJumping the character continues to go up as long as the jump button is pressed.

xMove = 0;
yMove = 0;

if (handler.getKeyManager().left) xMove -= movementVelocity * deltaTime;
if (handler.getKeyManager().right) xMove += movementVelocity * deltaTime;
if (handler.getKeyManager().jump && onFloor && !isJumping) {
    yMove += jumpingVelocity * deltaTime;
    isJumping = true;
}
else{
   isJumping = false;
}
// gravity
yMove += gravity * deltaTime;
0 Answers
Related