You are on page 1of 4

9/25/2014 Platformer Physics 101 and The 3 Fundamental Equations of Platformers | error 454 1/4
By Zachary Burke | October 23, 2013
Platformer Physics 101 and The 3 Fundamental
Equations of Platformers
There are tons of tutorials out there on doing platformer physics andimplementing various types of
platformers. What there seems to be lacking is a tutorial on how to choose good values for your
platformer physics.
This article will present some core physics equations in a new light! I will even be so bold as to christen
these equations as The Fundamental Equations of Platformers. The sample code here is presented in
LUA and for my prototyping I am using the ShiVa 3D game engine.
When designing physics for a platformer, the 2 fundamental values required are:
1. The strength of gravity
2. The initial velocity of a jump
With these values, were able to use the the kinematic equations to make a character jump and
eventually touch the ground again.
Basic Physics
3/22/2014 Please see comment by Ricky below. These simple equations are the calculus versions
broken down for simplicity, not the kinematic equations.
As a refresher, the 2 basic equations well use are:

This would be a typical implementation.
-- Set Y velocity to the jump velocity
this.nVelocityY( this.kVelocityJump )
1 -- Apply gravity every frame
Handle the jump Lua
Apply Gravity Lua
9/25/2014 Platformer Physics 101 and The 3 Fundamental Equations of Platformers | error 454 2/4
This code is at the heart of platformer physics, but when it comes down to it, these equations alone
kind of suck at being useful. Picking random values isnt the best way to get a good feeling platformer.
Lets look at a method that will help get you started with initial physics values.
The Fundamental Equations of Platformers
What makes more sense is to calculate gravity and initial jump velocity by picking 2 simple properties of
the universe:
1. Max jump height
2. Time to reach max height
Which leads us to the first two fundamental equations:

So what weve defined above are:
gravity as a function of the time to reach the top of the jump andmaximum jump height.
initial jump velocity as a function of gravity and maximum jump height
See the Derivations
Early Jump Termination
Edited 3/5/2014
As reader Chue points out, the equations below dont work unless gravity is negative. This is true
and was an oversight on my part. You could redefine the above equation for gravity and just tack
a negative sign on it. This also means that the equation for jump velocity is going to yield an
imaginary number (square root of a negative number), you can just throw that imaginary part
away. Ive updated the equations below to show that gravity is being plugged in as a negative
local dt = application.getLastFrameTime( )
local newVelocityY = this.nVelocityY( ) - this.kGravity
local distanceToMoveY = newVelocityY * dt

-- Assuming collision detection was ok, move the actor
object.translate( this.getObject( ), 0, distanceToMoveY
this.nVelocityY( newVelocityY )
9/25/2014 Platformer Physics 101 and The 3 Fundamental Equations of Platformers | error 454 3/4
The end numbers havent changed, I just failed to show my work. The spreadsheet at the end of
the article was not affected.
There are a few ways to do early jump termination but I am going to propose a method that is based on
a single parameter, minimum desired jump height. The idea is to calculate the downward velocity
required to achieve this minimum height. I now present the 3rd fundamental platformer equation
(which is a well known kinematic equation):
To use this, we choose our minimum jump height of 1 unit and we arrive at:
So then in code, when a player releases the jump key, youd do the following:
The one caveat with this method is that, depending on your world, you may set a minimum jump height
that is impossible for a human to hit. Because obviously we have limitations, like not being able to press
and release a key much faster than 200 milliseconds. So, as a friendly check, we can calculate the last
possible second that a jump can be terminated using this equation:
To prove out the equations and method, I did my best to recreate the physics from Mario 1 inside the
ShiVa 3D game engine. Based on my reverse engineering efforts (see details below) I arrived at the
following values:
Max Jump Height = 4 units
Time to reach max height = 0.44 seconds
Minimum jump height = 1 unit
if( this.nVelocityY ( ) > 0 ) then
-- Set velocity to whatever is smaller, termination velocity or current velocity
this.nVelocityY ( math.min ( this.kJumpVelocityTermination
Terminating a jump Lua
9/25/2014 Platformer Physics 101 and The 3 Fundamental Equations of Platformers | error 454 4/4
So plugging these into equations 1, 2 and 3 we get
Now see it in action, spacebar jumps.