Smooth value damping

Started by
4 comments, last by bzroom 14 years, 2 months ago
I'm trying to come up with a class to smoothly interpolate a current value to a target value. Rather than just stepping towards the target at some interpolation rate (this gives the behavior of deceleration on arrival at the target), i'd like to have the interpolation accelerate away from the current value as well. The target is constantly changing, therefore it doesnt make sense to remember an initial position or any other time based interpolation. The starting point from the blend is always the current value and the destination is the target value. I'm storing a value velocity. This velocity is accelerated and decelerated to reach the target. There are some nastynesses with this approach (blending has momentum, direction changes of the blend take a while to change directions) so i'm looking for any other ideas or suggestions. Anybody have any resources for value-smoothing techniques?
Advertisement
It might not be exactly the same problem, but you might find some relevant information in this recent thread.
I haven't read the thread that jyk linked, but I think you can simply accelerate towards the target at a constant rate until you get to the point where braking at that rate will make you arrive there with 0 speed. If this is not clear, I can try to write some code. Well, it will have to wait until tomorrow because I am flying to Europe tonight.

The standard approach is a critically-damped PD controller. It's simple to implement and quite robust in the face of arbitrary target changes. The only real problem is that it approaches the target asymptotically. If coming to an absolute stop in a short period of time is important for you, you'll need a slightly more complicated approach.
Our smooth values are based on the article "Critically Damped Ease-In/Ease-Out Smoothing", in Game Programming Gems 4, by Thomas Lowe I believe. They work great!
Yea that's what i did. Well basically, the critical damping part was a little out of my league so I just chopped it out. So i'm left with this weird looking PD controller I found on that cbloom site.

velocity += P * ( (target - current) + D * -velocity );
current += velocity * dt;

P = 10
D = 0.5

Work pretty nice

This topic is closed to new replies.

Advertisement