Consider the following statement for updating the velocity of a physical object during the integration process in a game:
velocity = velocity * 0.999f + acceleration;
Multiplying the velocity by a value slightly less than one is called "damping" and 0.999f
is the "damping factor". It is said that damping is necessary to remove excess energy caused by numerical instability.
I don't understand this. I could also use 1.001f
as the "damping factor" and make the claim that it is for adding missing energy (as opposed to exceeding energy) caused by numerical instability:
velocity = velocity * 1.001f + acceleration;
Right? What am I missing?
I'm not talking about drag forces here, am I? Well, after all, a 0.999f
drag factor is removing a part proportional to the velocity. Is the damping just a drag force?
The damping factor 0.999f or
DAMPING
is theα
in the digital low-pass filter to smooth the calculated velocity.OP has
What is missing is the implied passage of time scale down by 1/1000.
The
t*0.001
is1.0
and is certainly already factored in the period of updates and the units used to expressacceleration
andvelocity
.An alternative would used real units and let the compiler see
* (mm_to_m * UPDATE_PERIOD * DAMPING)
is scaling by 1 and trust efficient code will be emitted.