0
\$\begingroup\$

I want my character to always jump a constant height, let's say 3 meters. Also character has double jump ability so he can jump max 6 meters. For example, let's say I have pressed jump key while player is on the ground, and as soon he reaches 1 meter in height, I press jump key again and he performs double jump and reaches 4 meters.

I am really new to box2d and I have figured out that I can make my character jump using body.applyForceToCenter(new Vector2(0, 700), true) but I do not know how much force I need to apply in order to make my character jump exactly 3 meters and perform double jump to jump again exactly 3 meters.

I think what I really need here are just formulas...

\$\endgroup\$
1
  • \$\begingroup\$ if you want exactly 3 meters, using physics is not what you want. How high he goes will depend on the framerate if you just use an impulse and let the engine handle it. Quake 3 suffers from this problem; players jump different heights depending on the framerate their engine is set to. \$\endgroup\$
    – Almo
    Commented Dec 18, 2016 at 21:06

1 Answer 1

0
\$\begingroup\$

Formulas:

y = g * t^2 + Vi * t + Iy

V = 2 * g * t + Vi

In another form...

Vi = (y - g * t^2 + Iy) / t

Vi = V - 2 * g * t

To find the first jump initial velocity, you set y = 3, and V = 0, and solve for t which is 0.553, use that to solve for Vi which is 10.84988

The second jump is a little more involved.

Vc = V, and Iy = y, at the beginning of the double jump

You set Iy = the current y, y = 6, V = 0, then solve for the new Vi, subtract the current velocity Vc from the new Vi giving the velocity boost required to reach 6 meters.

Algebra hand waving:

(y - g * t^2 + Iy) / t = -2 * g * t

y - g * t^2 + Iy = -2 * g * t^2

y + Iy = -g * t^2

(Iy - y) / g = t^2

t = sqrt((Iy - y) / g)

Vi = -2 * g * sqrt((Iy - y) / g)

double jump boost in velocity is Vi - Vc

\$\endgroup\$
1
  • 2
    \$\begingroup\$ This answer could really benefit from some variable explanations for users that are not that familiar with physics in general. \$\endgroup\$
    – Charanor
    Commented Jan 23, 2017 at 21:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .