Sign in to follow this  
bzroom

Smooth value damping

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this