# Frame independent acceleration

To make my game fps independent I move entities with

pos += speed * time


where time is the delta time since last frame.

That works perfectly well with speed but how do you do that with acceleration?

• How are you currently doing acceleration? Typically acceleration is constant to simplify things. If your acceleration was constant, it would already be independent of time. Jun 5 '12 at 7:35
• Well I'm not doing any acceleration, it is full speed or nothing. I'm asking as I'm doing a platformer and I want to use acceleration to smooth movements and player shouldn't be able to jump farther just because the game runs sluggishly / faster on his PC :-) Jun 5 '12 at 7:57
• Here's an interesting (and classic) article: gafferongames.com/game-physics/integration-basics Jun 5 '12 at 12:19

You'll likely be using constant acceleration. So no need to worry! The derivative of constant acceleration with respect to time is 0. That means it doesn't change with respect to time, so it doesn't matter what your frame rate is. If you were using variable acceleration you'd set up your equation like:

acc += jerk * time //only needed if your acceleration isn't constant
speed += acc * time //calculates the current velocity given the acceleration
pos += speed * time //calculates the position given the current velocity


The jerk is the rate of change in your acceleration.

You may want to check out the equations of motion.

EDIT

Since your math is coming back to you, you may remember that using the Euler form above is fairly inaccurate. So you may remember this little integration with respect to time process from physics:

1. a = a
2. v = at + v0
3. s = .5at^2 + v0*t + s0

Where: a=acceleration, v=velocity, v0=initial velocity, s=position, s0=initial position, t=time

If you derive your position using that equation instead, you'll get far more accurate results.

• Oh yes it all comes back to me now (that old math stuff) Thanks! Jun 5 '12 at 12:57