Lerping, What Does it do and what are ways I can use it?

I’m trying to learn lerping right now. So far, I only learned how to Lerp Parts to other parts. I want to learn what else I can lerp and how

2 Likes

Lerping basically moves a part to a certain place. It takes 2 arguments: the place it’s going to go to (CFrame), and the time it takes to get there. For example:

yourpart:Lerp(anotherpart.CFrame, 1)

4 Likes

lerping interpolates two values. in this case it means to interpolate a cframe matrix but you could get the same effect by doing cframeA + (cframeB-cframeA) * t. t is what’s known as a parametric term and it has a domain from 0 to 1. If we treated these as linear affine transformations it makes a lot of sense why it is this. We have a displacement vector if we treated the data points as vectors and therefore we get that our parametric term is 0 or 1. if we multiply it by 0 we get the tail and if we multiply it by 1 we get itself of course. + the tail is just so it works in our coordinate space, cartesian.

3 Likes

Lerping is the interpolation between 2 values, not just positions. Given 2 values and a 0 to 1 number called alpha, it will give you a value that is somewhere in between the 2 input values.

For example: 5 and 15 with the alpha value 0.5. This will give you the value 10.

The general formula for interpolation is start + (goal - start) * alpha, start being the smaller number and goal being the larger one.

Based on the example above, the equation would look something like this:
5 + (15 - 5) * .5
Which equals to the value 10.

Note that the :Lerp function exists for many other kinds of values, such as Color3

1 Like

Like the camera for an example, how would I lerp that?

1 Like

The camera uses CFrame which also has a :Lerp function

image

can do something like

local c1 = CFrame.new(-50, 10, 0) * CFrame.Angles(math.rad(90))
local c2 = CFrame.new(100, 50, -50)
workspace.CurrentCamera.CFrame = c1:Lerp(c2, 0.75)
2 Likes

What is CFrame.Angles?

also why are you multiplying it by c1’s CFrame?

1 Like

This is getting off-topic so you should just create a new thread about this

1 Like

In simple terms; it’s simpler way of tweening one part to another. Or, literally the same thing.

1 Like