How does Lerping work?

Hello! This is probably my Trying to become a Intermediate scripter day 4, So… I’m trying to learn lerping, The issue is I cant find any tutorials at all on it, I know only a little bit about it and that’s it.

How does it work? ( please be exact )

also, how would I do this with the player camera?

There are many online resources that you can learn from. Here’s a specific video that you might like: What Is CFrame? | Roblox CFrame Tutorial | LookVector, Angles & More! - YouTube
It goes in-depth about CFrames and lerping with timestamps included.

2 Likes

This should really help me! I’m very confused on CFrame to and I am Curious on LookVector and the angles part, Thanks!

Just a reminder that you can visit the Developer Hub or search for an online tutorial like the one that @TheTypicalDoge provided before posting on the forum. Here’s a link to the CFrame docs: Understanding CFrames, CFrame Math Operations and CFrame

1 Like

Just search Roblox Studio Lerp and the first thing you will find is probably this

The devhub didn’t show me anything related to lerping when I searched it up

Understanding CFrames didn’t help me and confused me more

a friend told me that I could do it an easier way, I stopped watching the video because I thought it had outdated info

Your friend apparently thinks that 0.1 * 1 = 1, but no, it’s actually 0.1 * 10 = 1! Wow I know that’s just crazy (for loops). It doesn’t have outdated info.

No, that was my code, he was just correcting me.

also, that’s what the dev king wrote

What I meant is that for i = 0, 1, 0.1 will loop ten times because it starts from 0, continues up to 1 and each time it goes up by 0.1. If you can’t see his mistake and don’t know these basics, you can leave lerping for later, because you need basics like that. Also you might want to check your friend’s assumptions.

Linear interpolation is just a formula that finds a value that is some percent between two numbers.

If you want to find a number that is 24.56% between 43 and 95, we can use the formula:

local a = 43
local b = 95
local x = 0.2456 -- because percentages are a number / 100
result = a + (b - a) * x
-- which is the same as doing 55.7712 = 43 + (95 - 43) * 0.2456
1 Like

Lerping is just finding a certain percentage between two numbers. On a basic level, imagine you have a range between 0-30. You could lerp with these two parameters. The 0 would be the start and the 30 would be the goal. Lerping 10% of the way, or 0.1, would end up as 3. This last number, called the alpha, is basically how far you wanna go between the start and the goal. An alpha of 0.9, or 90%, would be 27.

1 Like

image

I assume you used a vector before. such as Vector3. a vector is just an arrow. there are two types: direction and position vectors.

let’s start with red and blue. we want a vector that is halfway between red and blue. first you have to get the vector that moves between red and blue. the direction that goes from position B to position R is R - B. this is purple.

the vector has to start at blue. if you add position to direction, you get the vector from a position going in a direction. B + (R - B), this is green.

to get something on a certain % of the vector is easy, just multiply the direction by the %. we want yellow to be 50% between red and blue. so the final direction is B + (R - B) * 0.5. that’s yellow.

final equation: A + (B - A) * t, a is the starting position, b is the ending position, t is the amount between. this works in 2d and 3d.