Comments and answers for "How to lerp with a changing "from" value?"
http://answers.unity.com/questions/1219333/how-to-lerp-with-a-changing-from-value.html
The latest comments and answers for the question "How to lerp with a changing "from" value?"Answer by Fressbrett
http://answers.unity.com/answers/1941303/view.html
You can also use the following formula to lerp a changing value to a target, such as in this case a transform.position during Update:
transform.position = Vector3.Lerp(transform.position, targetPos, 1f / (1f + dampen * Time.deltaTime));
Here, `dampen` is a value above zero, where zero will apply no dampening, and anything above zero will make the transition to the target value progressively slowerWed, 08 Mar 2023 01:50:42 GMTFressbrettComment by nerdares on nerdares's answer
http://answers.unity.com/comments/1219342/view.html
I also think I have found a solution:
I already had a value called MaxHunger which is 100;
I made a new value called currentHungerDelay. This will help update the third parameter in the lerp section as I need to keep the values of the first two parameters constant, like you said.
Therefore, I set currenthunger equal to the new lerp value and I made sure current hunger was not part of the parameters in there. Here's the code
public void Starve()
{
currentHungerDelay += Time.deltaTime;
if (currentHungerDelay >= HungerRate)
currentHungerDelay = HungerRate;
float t = currentHungerDelay / HungerRate;
CurrentHunger = Mathf.Lerp(MaxHunger, 0, t);
}Fri, 22 Jul 2016 00:22:56 GMTnerdaresAnswer by Bunny83
http://answers.unity.com/answers/1219337/view.html
Lerp won't work in that case. Both values need to be constant.
Instead of Lerp you might want to use [Mathf.MoveTowards][1] which does exactly what you want.
Lerp is implemented like this:
public static float Lerp(float a, float b, float t)
{
return a + (b - a) * Mathf.Clamp01(t);
}
while MoveTowards is implemented like this:
public static float MoveTowards(float current, float target, float maxDelta)
{
if (Mathf.Abs(target - current) <= maxDelta)
{
return target;
}
return current + Mathf.Sign(target - current) * maxDelta;
}
[1]: https://docs.unity3d.com/ScriptReference/Mathf.MoveTowards.htmlThu, 21 Jul 2016 23:52:27 GMTBunny83