Skip to content
ByteAtATime

Reverse-Engineering The Perfect Jump

Published: at 06:00 PM

Have you ever jumped in a platformer and thought, “Wow, that jump just feels right”? Alternatively, maybe you’ve made a game that has an unnatural or floaty jump. How can we make it feel more responsive and fun?

The math behind a jump is surprisingly simple! This article aims to show you how it works; by the end of it, you’ll be able to make something like this:

Interactive Jump Simulation
72px

Gravity: 574.40 px/s² | Initial Velocity: 287.20 px/s

The Core Ingredients

When you’re designing a jump, it usually boils down to two key parameters:

  1. Jump Height (hh): How high should the character reach at the very peak of their jump?
  2. Time to Apex (tapext_{apex}): How long should it take for them to get to that highest point?

By tuning these two parameters, you can make a jump feel more responsive and fun. With some simple math, we can figure out how to calculate the underlying physics we need.

The Physics of Up and Down: A Quick Guide

To build our jump, we need to talk about how things move, especially under the influence of gravity. Gravity is an acceleration (aa) — it’s constantly changing the player’s velocity, pulling them downwards. We’ll call the strength of gravity gg.

Now, if we know this constant pull of gravity, how do we figure out our player’s velocity (vv) (how fast they’re moving up or down) and their position (yy) (their height) at any given moment?

Thankfully, physicists have gifted us some handy formulas for when acceleration is constant (like gravity in our simple jump model). If our character starts their jump with an initial upward velocity (v0v_0) and gravity (gg) is pulling down (so we’ll treat its effect as negative):

  1. Velocity at any time tt: v=gt+v0v = -gt + v_0

  2. Position (height) at any time tt: y=12gt2+v0ty = -\frac{1}{2}gt^2 + v_0t

Jump Parabola: v₀ and g

Observe how initial velocity (v₀) and gravity (g) affect the dinosaur's jump path.

Calculated from settings: Time to Apex: 0.50 s | Max Jump Height: 62.5 px

Finding the Peak: The Jump Apex

Our jump is primarily controlled at its apex. This is the moment when the character stops moving up and is just about to start coming down. In other words, their vertical velocity is momentarily zero.

We can use our velocity equation (v=gt+v0v = -gt + v_0) and set v=0v=0 to find the time it takes to reach this apex (tapext_{apex}):

0=gtapex+v00 = -gt_{apex} + v_0

Solving for tapext_{apex} (the time to reach the apex):

tapex=v0gt_{apex} = \frac{v_0}{g}

This tells us that the time to reach the peak depends on how powerful the initial upward jump (v0v_0) is and how strong gravity (gg) is. Stronger gravity or a weaker initial jump means reaching the peak faster.

Now that we know when the apex occurs, we can plug this tapext_{apex} back into our position equation (y=12gt2+v0ty = -\frac{1}{2}gt^2 + v_0t) to find out how high the jump actually goes. This height is our desired jump height, hh:

h=yapex=12g(v0g)2+v0(v0g)=12gv02g2+v02g=v022g+2v022gh=v022g\begin{align*} h = y_{apex} &= -\frac{1}{2}g\left(\frac{v_0}{g}\right)^2 + v_0\left(\frac{v_0}{g}\right) \\ &= -\frac{1}{2}g\frac{v_0^2}{g^2} + \frac{v_0^2}{g} \\ &= -\frac{v_0^2}{2g} + \frac{2v_0^2}{2g} \\ h &= \frac{v_0^2}{2g} \end{align*}

This is a pretty cool result! It shows that jump height is directly related to the square of the initial velocity. If you double your initial jump speed, you’ll go four times as high (as long as gravity stays the same).

Designing Jumps: Working Backward from Our Goals

These equations are great, but as game designers, we often think differently. We usually know the experience we want: “I want my character to jump this high (hh) and take this long (tapext_{apex}) to get there.”

So, how do we find the initial velocity (v0v_0) and gravity (gg) needed to achieve our desired hh and tapext_{apex}? We can use the two key relationships we just found:

  1. tapex=v0gt_{apex} = \frac{v_0}{g}
  2. h=v022gh = \frac{v_0^2}{2g}

If you’re happy to skip the algebraic shuffle, here are the “golden formulas” you’ll need:

  • Gravity (gg): g=2htapex2g = \frac{2h}{t_{apex}^2}
  • Initial Velocity (v0v_0): v0=2htapexv_0 = \frac{2h}{t_{apex}}

For those who enjoy seeing the gears turn, let’s quickly derive them. Our goal is to solve for gg and v0v_0 using hh and tapext_{apex}.

From tapex=v0gt_{apex} = \frac{v_0}{g}, we can rearrange to get v0=gtapexv_0 = g \cdot t_{apex}

Now, substitute this into the height equation h=v022gh = \frac{v_0^2}{2g}:

h=(gtapex)22gh=g2tapex22gh=gtapex22\begin{align*} h &= \frac{(g \cdot t_{apex})^2}{2g} \\ h &= \frac{g^2 \cdot t_{apex}^2}{2g} \\ h &= \frac{g \cdot t_{apex}^2}{2} \end{align*}

And solving for gg: g=2htapex2g = \frac{2h}{t_{apex}^2} Voila! That’s our gravity. Now plug this gg back into v0=gtapexv_0 = g \cdot t_{apex}:

v0=(2htapex2)tapexv0=2htapex\begin{align*} v_0 &= \left(\frac{2h}{t_{apex}^2}\right) \cdot t_{apex} \\ v_0 &= \frac{2h}{t_{apex}} \end{align*}

And there’s our initial velocity! These two formulas are your design toolkit. Decide how high and how quick-to-peak you want your jump, and these tell you the physics values to make it happen.

Putting It All Together

Let’s recap the process for crafting a great-feeling jump:

  1. Define Your Goal:

    • What’s the desired maximum jump height (hh)? (e.g., 3 units)
    • How long should it take to reach that height (time to apex, tapext_{apex})? (e.g., 0.5 seconds)
  2. Calculate Your Base Physics Parameters:

    • Gravity (gg): g=2htapex2g = \frac{2h}{t_{apex}^2}
      • Godot: g = 2 * h / t_apex**2 (or g = 2 * h / pow(t_apex, 2) if you’re using Godot 3)
    • Initial jump velocity (v0v_0): v0=2htapexv_0 = \frac{2h}{t_{apex}}
      • Godot: v0 = 2 * h / t_apex
  3. Implement in Your Game Engine:

    • When the jump button is pressed, set the character’s vertical velocity to v0v_0.
      • Godot (CharacterBody2D): velocity.y = -v0
    • Every frame/physics update, apply gravity to the character’s velocity.
      • Godot (CharacterBody2D): velocity.y += g * delta
  4. Tune, Test, Iterate!

    • Playtest relentlessly. Can the player reach the intended height? Do they feel like they can control the jump?
    • Adjust hh and tapext_{apex}. Game feel is often found in these small iterative tweaks.

Did you like this article? If so, I would appreciate it if you could sign up to my newsletter below. No spam, I promise!

Credits

First of all, I would like to credit Arks, the creator of Dino Characters, the adorable dinosaurs featured in this post.

I would also like to thank GMTK for his post Behind The Code, explaining some of the logic behind the jump physics in his platformer toolkit.