# Single and Double Jump with single button.

I want to make Single Jump on Single Tap and Double Jump on Double Tap. My problem is that if I make double Tap on ground then it’s fine but if I make first Tap on ground and second Tap in Air then Player gain more height then usual As in image 1.

I want to Make my jump like in Image 2, No matter from which point user gives second Tap, player Always get a specific height.

I Used both Impulse and Linear velocity to make Jump but my problem did not solved.

-
The seconds image is no longer available. – nathan Nov 7 '12 at 11:57
also, the first image isn't really descriptive.. – Jari Komppa Nov 7 '12 at 12:26

This really depends on how you want to implement the mechanic. For me, a common "double jump" would be a second jump in mid air, if you're still on your way up. As such, I'd probably do something like this:

``````// dY is my vertical velocity; positive is pointing upwards
if (keyTapped(JUMP)) {
if (onGround()) {
dY = 10;
doubleJumped = false;
}
else if (dY > 0 && !doubleJumped) {
dY = 10; // the second jump
doubleJumped = true;
}
}
``````

Another idea would be an intuitive jump height based on how long ("hard") you press the jump key:

``````// jumpFrames is a counter to count the number of logic steps after starting the jump
if (keyDown(JUMP)) {
if (onGround()) {
jumpFrames = 0;
dy = 5;
}
else if (jumpFrames++ < 5) {
dY += 1;
}
}
``````

Both snippets are untested, but should work:

• The first one allows you to jump and then jump again while you're still ascending.
• The second one allows you to jump higher if you hold down the button for longer.

Both snippets assume there's some kind of friction/gravity slowing your velocity down again. The actual values might depend on your physics model.

-

It's hard to say with one image lacking, but maybe something like setting a target height? Like, if you hit the jump button while on the ground, target height is set to h, and if you hit it while already jumping, target height is set to 2h.

-