What is the best way to smoothly update a float?
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:
(The first node branch is connected to Event Tick). As you can see it is very messy... Is there a way to use a Timeline or something like that to do what I want?
Perhaps write your own function to do this?
ie Create a variable (float) named updateRate and another (float) targetValue.
targetValue = newValue
updateRate = (NewValue-Currentvalue)/Time
In the Tick event, do this: CurrentValue = min(CurrentValue+(updateRate*deltaDeconds), targetValue)
You will do the above only if (updateRate != 0 AND CurerntValue != targetValue)
I think this will give you a linear increase.
Follow this question
Once you sign in you will be able to subscribe for any updates here