Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.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.Image 2

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

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

2 Answers 2

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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.