How can I apply "damping" to a value

Hi

I have a value x that is modified by another value y every frame. This results in x increasing or decreasing. The value of y can change, as it is itself dependent on other factors.

The problem is that I don’t want x to change immediately in response to a change in y, but slowly. So for example, if x = 2, and y modifies it to 4, I want x to start trending towards 4 with a Bezier-like smoothness, then stop when it reaches 4.

Is there a pattern or method that can be put to this purpose? Any help would be appreciated.

/Jason

You could multiply y by a value evaluating x in an AnimationCurve

That’s kind of what MoveTowards does.

Mathf.SmoothDamp comes to mind.

Have you thought of Mathf.lerp( float a, float b, float t) ?

First param is the first number, second is the second, and t is how far between you want the result - 0 is the first, 1 is the second. So if you define a speed that is low, multiple by Time.deltatime, you could use it as the third parameter and mess with the speed until you get what you like.

Just my 2 cents.
Thanks!

Thanks everyone.

I think Baste nailed it with Mathf.SmoothDamp.

The other suggestions were helpful though.