Lerp is linear, if t
changes at a constant speed, so does the output.
Wrong-lerp is an application of lerp that produces smooth, yet imperfect movement towards a target value.
value = Mathf.Lerp(value, target, Time.deltaTime * speed);
Accompanied by such phrases like:
"Your using Lerp wrong."
This common hacky application easily creates smooth motion.
speed
isn't speed, it's a vague quickness.target
is approached, it isn't reached. This moves a vague proportion towards it instead.deltaTime
used, its function here is only a vague improvement.Vague is the takeaway from this usage.
If you don't need exact outcomes or durations and aren't too worried about differences across frame rates, applying lerp like this is a common creative way to smooth movement.
// speed: 10
value = Mathf.Lerp(value, 1, Time.deltaTime * speed);
Using a more complex t
can solve frame rate dependency problems.
// decay: 10
value = ExponentialDecay(value, target, decay, Time.deltaTime);
Using Pow
is a more expensive approach, so consider your use cases.
If you are concerned about any of the downsides, consider alternatives like:
*Certain libraries will have their own tweening libraries built-in. For example, UI Toolkit has USS transitions.