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:
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:
- Jump Height (): How high should the character reach at the very peak of their jump?
- Time to 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
This article aims to explain not only *what* the physics are, but also *why* they are the way they are. Although I recommend reading the whole article, if you're just looking for a quick recipe, you can skip to the next section.
To build our jump, we need to talk about how things move, especially under the influence of gravity. Gravity is an acceleration () — it’s constantly changing the player’s velocity, pulling them downwards. We’ll call the strength of gravity .
Now, if we know this constant pull of gravity, how do we figure out our player’s velocity () (how fast they’re moving up or down) and their position () (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 () and gravity () is pulling down (so we’ll treat its effect as negative):
-
Velocity at any time :
-
Position (height) at any time :
The formulas for velocity () and position () under constant acceleration (like gravity) come from basic calculus. If you’re not familiar with calculus, feel free to skip this section and trust the formulas presented in the main text!
We start with the definition of acceleration: Acceleration () is the rate of change of velocity () with respect to time (). Since gravity () acts downwards, and we’re considering itself as a positive value (e.g., 9.8 m/s²), the acceleration due to gravity is .
1. Finding Velocity ():
To get velocity from acceleration, we integrate acceleration with respect to time:
Integrating both sides:
Since is a constant:
Here, is the constant of integration, representing the initial velocity of the jump. At time (the start of the jump), the character has an initial upward velocity, which we’ve called . So, . Plugging this into our equation:
Thus, the velocity at any time is:
2. Finding Position ():
Velocity () is the rate of change of position () with respect to time ():
Substitute the expression for we just found:
To get position from velocity, we integrate this expression with respect to time:
Integrating both sides:
is another constant of integration. We determine its value using the initial condition for position. For simplicity, we usually define the starting height of the jump as at time . So, . Plugging this into our equation:
Thus, the position (height) at any time , assuming the jump starts from , is:
And that’s how we arrive at the core kinematic equations used for our jump physics, starting from the constant downward acceleration of gravity!
Observe how initial velocity (v₀) and gravity (g) affect the dinosaur's jump path.
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 () and set to find the time it takes to reach this apex ():
Solving for (the time to reach the apex):
This tells us that the time to reach the peak depends on how powerful the initial upward jump () is and how strong gravity () 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 back into our position equation () to find out how high the jump actually goes. This height is our desired jump height, :
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 () and take this long () to get there.”
So, how do we find the initial velocity () and gravity () needed to achieve our desired and ? We can use the two key relationships we just found:
If you’re happy to skip the algebraic shuffle, here are the “golden formulas” you’ll need:
- Gravity ():
- Initial Velocity ():
For those who enjoy seeing the gears turn, let’s quickly derive them. Our goal is to solve for and using and .
From , we can rearrange to get
Now, substitute this into the height equation :
And solving for : Voila! That’s our gravity. Now plug this back into :
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:
-
Define Your Goal:
- What’s the desired maximum jump height ()? (e.g., 3 units)
- How long should it take to reach that height (time to apex, )? (e.g., 0.5 seconds)
-
Calculate Your Base Physics Parameters:
- Gravity ():
- Godot:
g = 2 * h / t_apex**2
(org = 2 * h / pow(t_apex, 2)
if you’re using Godot 3)
- Godot:
- Initial jump velocity ():
- Godot:
v0 = 2 * h / t_apex
- Godot:
- Gravity ():
-
Implement in Your Game Engine:
- When the jump button is pressed, set the character’s vertical velocity to .
- Godot (CharacterBody2D):
velocity.y = -v0
- Godot (CharacterBody2D):
- Every frame/physics update, apply gravity to the character’s velocity.
- Godot (CharacterBody2D):
velocity.y += g * delta
- Godot (CharacterBody2D):
- When the jump button is pressed, set the character’s vertical velocity to .
-
Tune, Test, Iterate!
- Playtest relentlessly. Can the player reach the intended height? Do they feel like they can control the jump?
- Adjust and . 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.