Smooth Lerp ?

Greetings,

is there a special Lerp function that isn’t completely proportional ?

The red arrow is the normal, straightforward Lerp.
The blue is the Lerp I’d like.

Must I code it by myself ? Or has anyone seen something like that ?

I don’t know a curving API is in Unity or not. If you do have to program your own, I’m guessing it’ll be some implementation of bezier curves: Bézier curve - Wikipedia

Use Mathf.SmoothStep…instead of having

Mathf.Lerp(start, end, t);

where t goes from 0 to 1, have this:

Mathf.Lerp(start, end, Mathf.SmoothStep(0.0, 1.0, t));

–Eric

4 Likes

Hmm…the description seems to fit my need. I will try it. Thank you ! :wink:

You could also take a look at iTween and/or the Interpolate functions on the wiki. Both make it trivial to get non-linear interpolations of various types.

Eric, does your code not do the exact same thing as Mathf.SmoothStep(start, end, t); but with longer, more difficult to understand code that isn’t as performant?

Correct me if I’m wrong - I’m very new to Unity, but the mathematician in me is screaming that they’re the same.

Sorry if I am resurrecting an old thread, but as I came from Google I feel like this answer should be answered:

SmoothStep uses smoothing at the limits, i.e. not linear interpolation. You can read about it here:
http://docs.unity3d.com/ScriptReference/Mathf.SmoothStep.html

I believe the forum engine changed in the year from when I wrote my post until you read it. I was asking whether

Mathf.Lerp(start, end, Mathf.SmoothStep(0.0, 1.0, t));

and

Mathf.SmoothStep(start, end, t);

Were the same, but the new forum engine displays quotes differently, hiding the portion of the quote I was actually referencing. I modified my prior post to make it clearer that that was what I was asking about.

If you work through the maths it’s exactly the same. I’m not sure why he did it like that.

Ah. I see now. Thank you. I misunderstood the question. :slight_smile:

On the other hand, Eric5h5’s example can be productively plugged into other Lerp’s:

Vector3.Lerp(start, end, Mathf.SmoothStep(0.0, 1.0, t));
2 Likes