Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
    
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. –  Byte56 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 :-) –  Valmond Jun 5 '12 at 7:57
2  
Here's an interesting (and classic) article: gafferongames.com/game-physics/integration-basics –  Alayric Jun 5 '12 at 12:19
add comment

1 Answer

up vote 6 down vote accepted

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.

share|improve this answer
    
Oh yes it all comes back to me now (that old math stuff) Thanks! –  Valmond Jun 5 '12 at 12:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.