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


Decay / friction over time

Recommended Posts

I know this is probably really simple, but I appear to have a mental block on it - I have a velocity that needs to decay over time due to friction. The nice simple way is to just multiply it by something like 0.98 every frame which produces exactly the right kind of behaviour. However this is obviously tied directly to the framerate. I''m using time-based movement so somehow I need to use my time delta between frames but I have no idea how to decay the velocity which will produce the same output. Ideas?

Share this post

Link to post
Share on other sites
This approach gives an exponential decay, but in reality, the decay of the velocity caused by friction is linear.

With the exp. approach, you have to give a number (say D), like 0.98, that describes, what decay you want to achieve in a second. Then you can use the following formula for any dt:

new velocity = old_velocity * D^dt, D should be less than 1
So in this case for accurate result you need a power() operation.

With the linear (real) version the friction is actually a force, say F, which stops the object
F = m * a
a = F/m

With euler integration: new_velocity=old velocity + a * dt, and a should be negative, and F too in this case.

I prefer the latter solution. It''s morerealistic, and cheaper.

Share this post

Link to post
Share on other sites
eish, can''t remember exact formula right now, and got to run ... but

X = scale per second
T = time

so X=0.9 for 1 second = R=0.9
so x=0.9 for t=2 : R=0.9*0.9 = 0.81

R= ln(x*exp(t))
R= ln(t*exp(x))

can''t recall which, must go calc it...

then just multiply by R for timestep T, insted of fixed R=0.98 for fixed timestep T=0.01 or whatever

Share this post

Link to post
Share on other sites