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'm working on a 2D iPhone game using Corona (Trial version, so I can't use their forums). The game involves the character falling through the sky, and I'm trying to implement a "double jump" for the character, for him to be able jump up while falling. I'm using Corona's physics library to have the character fall, and so far the best method of having him jump is using the vertical impulse method

object:applyLinearImpulse(0, -0.4, object.x, object.y)

The problem I face is that when the character is just starting out (vertical velocity is low), he jumps really high, and when he's been falling for a while (vertical velocity is high), the jump is negligible. I'm guessing that the best solution is to use some sort of equation with the velocity as input to make the jump the same regardless of velocity, but I can't figure out what that equation would be.

Okay, so that's all my thoughts. The end question is, how exactly do you implement a double jump with physics? Is there a proper equation for my problem? Should I take a different approach? It's been done before in games like Smash Bros, so there's a repeatable solution, right?

share|improve this question

2 Answers 2

up vote 35 down vote accepted

Just set the vertical velocity to zero, and just call the same code you use to do the first jump.

share|improve this answer
4  
Oh. That...actually works pretty well. And so simple that I now feel foolish for not thinking of it. Oh well. Thanks! –  Jesse J May 20 '11 at 3:49
5  
It's often tempting to make things more complicated than they need to be :) –  Adam Harte May 20 '11 at 7:13
2  
elegant answer! –  lathomas64 May 20 '11 at 17:01

I'm not sure, but I think games like UT2K4 might use logic like this:
if (jumped already && !doubled jumped yet && !touching ground && velocity.up is approximately 0.0f) DoDoubleJump();

Where up is your y or z component (Depending on which one is up)
This means that your player can only do a double jump when they are at the maximum height of their first jump and are just about to start come down again.
I like this method because it creates a little bit of skill (You have to time it to happen inside of "velocity.up is approximately 0.0f").
Depending on what you want, you could bias "approximately 0.0f" towards positive numbers so they can only double jump when still moving up for example.

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.