This is probably massive overkill, but it may come in handy for somebody
Damping is usually implemented by multiplying the velocity of an entity by a constant each frame (usually about 0.9 so you lose 10% of the velocity each frame). Alternatively you can use "curvevalue" with a destination of zero, which works out to be the same.
The problem with this method is that the results vary massively depending on the frame-rate, so I decided to solve the equations properly for a variable timestep. I use a constant called 'f' which is the percentage velocity lost each second under zero external acceleration.
Working:
a = external acceleration
t = time
v = velocity
u = initial velocity
s = displacement since t=0
Actual acceleration is -f*velocity plus external acceleration
dv/dt = -f*v+a
Initial velocity (t=0) is given by "u"
v(0) = u
Solving the differential equation gives:
v = a/f + (u-a/f)*e^(-f*t)
Integrate that with respect to time to find displacement since t=0:
s = (a*e^(-f*t))/(f^2) + a*t/f - (u*e^(-f*t))/f - (a-f*u)/(f^2)
The example code:
sync on : sync rate 60
e# = 2.718281828459045
s1# = 100
s2# = 100
s3# = 100
f# = 0.5
t1# = 1.0/60.0
t2# = 1.0/120.0
t3# = 5.0/60.0
n = 0
do
u1# = v1#
s1# = s1# + (a#*e#^(-f#*t1#))/(f#^2.0) + a#*t1#/f# - (u1#*e#^(-f#*t1#))/f# - (a#-f#*u1#)/(f#^2.0)
v1# = a#/f# + (u1#-a#/f#)*e#^(-f#*t1#)
for i = 1 to 2
u2# = v2#
s2# = s2# + (a#*e#^(-f#*t2#))/(f#^2.0) + a#*t2#/f# - (u2#*e#^(-f#*t2#))/f# - (a#-f#*u2#)/(f#^2.0)
v2# = a#/f# + (u2#-a#/f#)*e#^(-f#*t2#)
next i
if n mod 5 = 0
u3# = v3#
s3# = s3# + (a#*e#^(-f#*t3#))/(f#^2.0) + a#*t3#/f# - (u3#*e#^(-f#*t3#))/f# - (a#-f#*u3#)/(f#^2.0)
v3# = a#/f# + (u3#-a#/f#)*e#^(-f#*t3#)
a# = (rightkey()-leftkey())*50.0
endif
dot s1#, 100
dot s2#, 120
dot s3#, 140
print "Velocity 1:", v1#
print "Velocity 2:", v2#
print "Velocity 3:", v3#
sync
cls 0
inc n
loop
The example simulates an entity experiencing damping on three different frame-rates. You can see that they all stay in line even though the third dot is simulated as though it has a 10x lower frame-rate than the middle dot. Using the normal method at this difference in frame-rate would result in a 55% difference in velocity between the slow computer and the fast computer after a single frame on the slow computer!
[b]