math tidbit: framerate consistent simple exponential animation
by Orion Elenzil · 01/18/2006 (5:11 pm) · 2 comments
To make the motion of thing smooth, i frequently do something like this:
Xcur = Xcur * slur + Xtarget * (1.0 - slur)
This is great but if you're running it once per frame, it's sensitive to framerate.
The following is some math to determine a value for slur which results in framerate-independant motion.
pseudocode:
Also,
calculating the framerate may be time-consumptive if you don't have it laying around already,
so you may want to only actually do that every 10 frames or so. - However, be sure calcSur has the correct framerate!
Xcur = Xcur * slur + Xtarget * (1.0 - slur)
This is great but if you're running it once per frame, it's sensitive to framerate.
The following is some math to determine a value for slur which results in framerate-independant motion.
pseudocode:
calcSlur(targetPercent, targetSeconds, currentSecondsPerFrame)
{
return mPow(targetPercent, currentSecondsPerFrame)/ (targetSeconds));
}Also,
calculating the framerate may be time-consumptive if you don't have it laying around already,
so you may want to only actually do that every 10 frames or so. - However, be sure calcSur has the correct framerate!
About the author
#2
This is a simple way to smooth out the motion of objects which otherwise move instantly from one spot to another, or which maybe just have a bit of jitter.
It gives an effect similar to attaching the object to a spring.
I like this type of animation because it's non-linear. That is, the motion is faster when the object is far from it's target location, and gets slower and slower as it approaches the target, so that the final 'landing' is very smooth.
One place i'm using it is i have a camera which looks at the player in a guiObjectView window.
There's buttons for switching where the camera is looking: head, body, or feet.
I'm using this slur-type code so that the transitions from looking at one part vs. another are animated smoothly instead of instantaneous cuts.
The problem with this slur-type code is that it's framrate-dependent.
The little bit of math i posted here fixes that.
01/21/2006 (12:19 pm)
Fair enough, it is a bit abstract.This is a simple way to smooth out the motion of objects which otherwise move instantly from one spot to another, or which maybe just have a bit of jitter.
It gives an effect similar to attaching the object to a spring.
I like this type of animation because it's non-linear. That is, the motion is faster when the object is far from it's target location, and gets slower and slower as it approaches the target, so that the final 'landing' is very smooth.
One place i'm using it is i have a camera which looks at the player in a guiObjectView window.
There's buttons for switching where the camera is looking: head, body, or feet.
I'm using this slur-type code so that the transitions from looking at one part vs. another are animated smoothly instead of instantaneous cuts.
The problem with this slur-type code is that it's framrate-dependent.
The little bit of math i posted here fixes that.

Torque Owner Stefan Lundmark