Comments and answers for "Linear Interpolation that is independent of frame rate"
http://answers.unity.com/questions/1482178/linear-interpolation-that-is-independent-of-frame.html
The latest comments and answers for the question "Linear Interpolation that is independent of frame rate"Comment by GambaDeveloper on GambaDeveloper's answer
http://answers.unity.com/comments/1833758/view.html
What a hell of a function that is! will come very handySun, 02 May 2021 02:59:26 GMTGambaDeveloperAnswer by Bunny83
http://answers.unity.com/answers/1482196/view.html
Your use of lerp is **not** a **linear interpolation over time**. Time.deltaTime can only be used to compensate linear processes. Taking 50% of the remaining is not a linear process but an exponential process. This can not be compensated with a linear factor as each iteration has a different effect on the outcome. Linear functions have a constant derivative while exponential functions usually have an exponential derivative.
<br>
To actually calculate the factor needed every frame to achieve a 50% drop per second you would need to take the "n-th" root of "0.5" where n is the current framerate. For example at a framerate of 60 frames per second you would calculate the "60th" root of 0.5 which is about "0.988514". If you multiply a value by this factor 60 times you effectively have multiplied it by 0.5. However calculating the "1/deltaTime"th root of your desired factor is a quite expensive operation. Specifically using `Mathf.Pow(0.5f, Time.deltaTime);`
<br>
The example given on the page you linked is actually a really bad example usage for lerp. If you want a gradually slowed down interpolation from the current value towards a target you want to use [Mathf.SmoothDamp][1] just like they mention at the very bottom of the page you linked.
private float speed = 0;
void Update()
{
light.intensity = Mathf.SmoothDamp(light.intensity, 8f, ref speed, 10f);
}
Note that this will bring the intensity to the value of "8" within 10 seconds. Also note that the speed variable is controlled by the SmoothDamp function and is used to save the state of the velocity between frames. You shouldn't set this value manually. Just make sure you have an actual variable that persists between two frames.
[1]: https://docs.unity3d.com/ScriptReference/Mathf.SmoothDamp.htmlMon, 19 Mar 2018 00:57:16 GMTBunny83Comment by meat5000
http://answers.unity.com/comments/1482193/view.html
Its in the $$anonymous$$anual!
And answered extensively.Mon, 19 Mar 2018 00:52:31 GMTmeat5000