What's the point of Lerp()?

What’s the point of Lerp() if you can just make a For Loop?

So I’ve been scrolling through tutorials on Youtube about Roblox studio and I came across lerping. In the video they showed how to use it but never told me why it was more useful then just using a For Loop and moving let’s say a part and .1 studs every .1 second.

Linear Interpolation (or Lerp) basically makes it easier for you when moving from Point A to Point B, it is used in Programming as a way to transition objects (like Colors, and Vectors) smoothly, or to a specific point between 2 or more other points, APIs such as TweenService uses Interpolation to smoothly transition said objects, except with more advanced versions of the Formula to have more visually appealing effects.
Think of it as a percentage to where the point will be, 0 is 0%, 0.5 is 50%, and 1 is 100%, when incrementing at 0.1, you are essentially moving up 10% at a time, if we have Point A starting at the Origin (0, 0, 0) and Point B at (100, 100, 100), 10% would be (10,10,10) as that is 10% away from point A, and 10% towards Point B.

If you are just moving in a linear path (such as the example abovel, or maybe changing the X axis from 0 to 10), there probably isn’t a good use there, but its a very useful tool to apply the calculated point rather than just doing the math yourself and then applying it as such, such as when you decide the move the object to a new location, the premade calulations wont work as intended, but the Ones Calulated using Linear Interpolation will, as its making the calulations while running the game.
Is also useful for maybe if the object is moving, and you need to apply “weight” to the object to transition slowly towards a point like a trail, it makes it easier for you to apply these effects.


A for loop is essentially just you telling the Computer to run a specific Command a specified amount of time, Instead of you having type the same code hundreds of times, you can just use a for loop, type the code once, have it run for a 100 times, and you’re done, its pretty simple.

Using a for loop:

  • Simplifies the Process (As stated)
  • Cleans your code
  • Looks more Professional
It basically does the work for you, instead of you telling the server to use wait() every fraction of a second just to apply a single position.
-- Bad Code
wait(.1)
-- code
wait(.1)
-- code
wait(.1)
-- code

-- This is time consuming, takes longer to modify
-- you need to change this every time you make an update

-- it also takes up for space, and looks ugly

-- Better Code

for index = 0,1, .1 do
    wait(.1)
    -- code
end

-- Instead of multiple lines
-- you can just tell the server to loop this code 10 times
-- and it will do it
-- Instead of you manually doing it
-- It also only needs to be modified once, for it to apply to all
-- 10 iterations (.1(10) = 1)

TLDR: The whole purpose is to make it easier for you.

2 Likes

thank you @DasKairo makes sense.

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