Jump to content
  • Advertisement
Sign in to follow this  
bzroom

Smooth value damping

This topic is 3054 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
It might not be exactly the same problem, but you might find some relevant information in this recent thread.

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!