Use Mathf.Lerp for real-time updated values

So I have a float called “val” that will get an updated value every 10 seconds. This value is sent in from another system via an open sound control.
I want to use Mathf.Lerp between each value so that it lerps between the previous value and the next value within 10 seconds to avoid a sudden jump from, say, 0.1 to 0.5. Is there anyway to use lerp between 2 values if they constantly change?
Thank you!

val=Mathf.Lerp(previous,current,(Time.time%10)/10);

You may want to use your own timer instead of Time.time so then it’s better in sync with your input data.

Smoothing movement between any two particular values:

You have currentQuantity and desiredQuantity.

  • only set desiredQuantity
  • the code always moves currentQuantity towards desiredQuantity
  • read currentQuantity for the smoothed value

Works for floats, Vectors, Colors, Quaternions, anything continuous or lerp-able.

The code: SmoothMovement.cs · GitHub