Question about lerping with 1 alpha

edit: fixed, i flipped the alpha as 0 instead of 1

when the alpha is 1, I’m trying to decide whether to use set or lerp.

does this:
followCam.position.lerp(camLerpingPoint, 1);

perform the same as:
followCam.position.set(camLerpingPoint.x, camLerpingPoint.y, camLerpingPoint.z);

I’m asking in terms of both behavior and performance.

They’re not the same.

followCam.position.lerp(camLerpingPoint, 0): Since the alpha is 0, it will do nothing, it will keep followCam.position value as it is.

followCam.position.set: Will set the camera’s position to the final camLerpingPoint value, it’s more equivalent to a lerp with an alpha of 1, followCam.position.lerp(camLerpingPoint, 1);

Performance wise, set is a tiny bit faster then lerp, but it’s irrelevant here, since you can’t replace lerp with a simple set, unless it’s not a lerp.

1 Like

my bad, i flipped the alpha in the example.

so does lerp with alpha 1 behave the exact same way as setting the position?

will both produce the same result in the next frame?

1 Like

If the alpha is 1 then yes they are equivalent, you can see it this way, 0 is the initial position, 1 is the final position, the rest is in between, and lerp stands for linear interpolation.

I suggest you initiate a discution with chatGPT or claude, it can explain it, sadly, better then me :sweat_smile:

Thanks! i had the same idea but I had to make sure.
as for the performance part, i guess i’ll take a look at the lerp source code and see how much of a performance impact it has compared to set.

It’s not an apple to apple comparison, lerp is more used for smooth animation, while set simply set the value.

You can also use copy as a better alternative to set, followCam.position.copy(camLerpingPoint)

I understand the use of lerp.
My use case is the Lerp multiplier is configured by the user.
So if the user passes 1, I’m thinking of doing a condition and using set instead of lerp to maximize performance.

1 Like