Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How does lerp() work?

Asked by 8 years ago

I understand it's interpolation, but how would you use it in a script?

1 answer

Log in to vote
1
Answered by 8 years ago

lerp takes a parts current cframe and generates a path with a number (alpha between 0 and 1) depicting the starting cframe and the end cframe (with other cframes inbetween 0 and 1). You would start this out with a simple Part

local part = Instance.new('Part', workspace)

You would then create a for statement to create a smooth CFraming

for i = 0, 1, 0.0001 do
-- Lerp here
wait(0.01) -- small numbers for Smooth CFraming
end

Next you would call the lerp method inside the for loop lerp can only be called as a method on CFrames

part.CFrame = part.CFrame:lerp(part.CFrame+Vector3.new(21,04,30),i)

Together it would look like

local part = Instance.new('Part', workspace)
for i = 0, 1, 0.0001 do
part.CFrame = part.CFrame:lerp(part.CFrame+Vector3.new(21,04,30),i)
wait(0.01)
end

Thats it really. have a nice time with your new knowledge!

0
I just want to clarify that the first argument is the goal CFrame Perci1 4988 — 8y
0
Yes Angels_Develop 52 — 8y
Ad

Answer this question