I’m trying to create a function which will take as inputs: NewValue and Time.
The goal of the function is to update a private float variable to NewValue, and it will smoothly update itself in Time seconds.
For example, the variable is set to 0 and I call the function with NewValue = 1 and Time = 1
So the variable will have to have the value “0.1” in 0.1 second, “0.5” in 0.5 second, and “1” in 1 second.
I wanted to use Lerp but the problem is that I can’t set how long it has to update it, and the smooth is not the one I want, because the value will be 0.1, 0.6, 0.9, 0.95, 0.99, 0.999… and I want 0.1, 0.2, 0.3…, 0.9, 1.
So I did a math function but I’m sure that’s not the best way to do it:
Thats normal, because Interp never reaches target value, just move value closer to target value and less distance i moves less closer, thats why you go this smooth effect out of it. You need to detect when value is 0.9999999 and correct it to 1 yourself. This function was made mainly for animation where 0.9999 values are irrelevent.