#### Archived

This topic is now archived and is closed to further replies.

# Frame-rate independent acceleration

This topic is 6105 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I want some sort of exponential decay. At the moment I''m using vx = vx * .999; but this is unreliable as frame rate changes. What do you suggest? - seb

##### Share on other sites
each frame before the anything is done grab the framerate. Then when you do the movement divide all your per second stuff by the framerate. That should produce an accurate effect.

##### Share on other sites
Yep, that''s how I do all of my other movement. Though I grab the milliseconds since last update and multiply speeds by this. But it''s all the same thing.

But that won''t work in this case.

- seb

##### Share on other sites
quote:
Original post by BSXrider
But that won''t work in this case.

It won''t?

##### Share on other sites
No. Look at the line of code I showed and explain how a similar effect can be done using framerate/time information.

- seb

##### Share on other sites
It will work, but you''re not using it properly.

Say you''ve got a velocity "v" in meters per second.

Say you''ve got a constant acceleration "a", in meters per second per second.

Every second:

v += a;

Therefore, every frame:

v += (a * frame_time);

If you think about what you''re doing (multiplying by .99 or whatever) you should see that the object will never come to a stop. This isn''t natural.

Instead, see if the object is moving, and if it''s not, apply a deceleration.

- Pete

##### Share on other sites
Hi,

http://www.gamedev.net/community/forums/topic.asp?topic_id=75233

i think this could solve your problem ...

##### Share on other sites
quote:
Original post by siaspete
If you think about what you''re doing (multiplying by .99 or whatever) you should see that the object will never come to a stop. This isn''t natural.

Nevertheless this is the behaviour I want. It will come to a stop because of rounding errors, and it''ll do so in a nice ease-out fashion.

- seb

##### Share on other sites
That''s possibly not the best approach. Fair enough it''s your software, but it''s best to code specific algorithms than to rely on what''s essentially a fault in the FPU.

##### Share on other sites
I''m not relying on it. It could never reach 0 and I wouldn''t be bothered. It''s just not important.

- seb

1. 1
Rutin
49
2. 2
3. 3
4. 4
5. 5

• 11
• 16
• 9
• 10
• 13
• ### Forum Statistics

• Total Topics
633003
• Total Posts
3009846
• ### Who's Online (See full list)

There are no registered users currently online

×