Help understanding lerp

So if you read the title, you know exactly what I’m trying to get. Can anybody explain how to lerp a bodymover? (e.g bodyvelocity) I know that you need to do

bodyVelocity.Velocity = bodyVelocity.Velocity:lerp(Vector3.new( ), 0.1)

But what do you put in the Vector3.new()? What does the 0.1 do? Thanks

The lerp function takes the Vector3 value it’s called on and returns a mid point between it and the first parameter (also a Vector3). The second parameter is alpha, its basically how “far” to lerp the two. For example, a lerp with 0.1 would return a vector that’s 10% of the distance to the inputted vector from the vector it’s called on.

tl;dr; it averages two Vectors, with the second parameter being the weight at which they are averaged.

lerp dia

Here is a the function written out:

local function lerp(va, vb, a)--vector2 lerp: va is the Vector lerp is called on, vb is the first parameter (a vector), a is the second parameter (alpha)
	return Vector2.new(va.x*(1-a) + vb.x*a, va.y*(1-a) + vb.y*a)
end

To answer you’re question, any vector can be the first parameter. For example, if you wanted to slow the velocity by 10% you could do:

bodyVelocity.Velocity = bodyVelocity.Velocity:lerp(Vector3.new(0,0,0), 0.1)

or if you wanted to average the velocity with another velocity you could do:

local velocity2 --set to second velocity
bodyVelocity.Velocity = bodyVelocity.Velocity:lerp(velocity2, 0.5)
2 Likes

For those who don’t know exactly what lerp is, it is linear interpolation. The alpha given will transition the original property from A to B.

1 Like