Non-linear lerp?

can you explain why this case it is a non-linear lerp and why we are not using slerp (we also didn’t use slerp for the rotation on the unit script)? thank you so much!

Actually, for the unit script, using Lerp instead of Slerp results in a bug where characters actually walk backwards when moving in certain directions. I don’t think Hugo changes this in the course, but it’s mentioned in several questions.

For the camera zoom, there a no direct issues with Lerp vs Slerp, so you may use either if you choose.

3 Likes

A lerp is a linear interpolation. It ‘moves’ from point a to point b over time t with a linear step. The reason this specific case is ‘non-linear’ is because we are continuously changing point a.

If we supply a = 10 and b = 20 to a lerp with t = 0.5, it will always return 15. However, here, we are changing a each time. Let’s use the result of the lerp in a and see what happens:

a = 10,    b = 20, t = 0.5 -> result = 15     (step = 5)
a = 15,    b = 20, t = 0.5 -> result = 17.5   (step = 2.5)
a = 17.5,  b = 20, t = 0.5 -> result = 18.75  (step = 1.25)
a = 18.75, b = 20, t = 0.5 -> result = 19.375 (step = 0.625)
etc.

As you can see, the change in the result becomes smaller and smaller - not linear. In mathematics the step will never reach 0. In computers, it will though.

In the lecture we are also calculating t, but Time.deltaTime will generally only have very small fluctuations so it is essentially still giving the same value for t. So, technically, we are not moving based on time t but based on position a. If you had to plot the positions on a graph you will see that we are slowing down the closer we get to the target position. A sort of ‘ease’ if you will.

They will look something like this


(Sorry, I’m too dumb to plot these in Desmos or something)

As for Slerp, there is a small caveat with slerp because it uses world-space (0,0,0) as its origin. See this

3 Likes

wow! thank you! that really helped! btw, how does “SmoothDamp” fit in to this? is it similar? thx!

thanks! so would changing this to slerp fix it?

No, for the same reasons Bixarrio outlined… The issue is that we’re changing the master values along with the progress.

2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms