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 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 GMTFressbrettAnswer 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