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

How to use CFrame:lerp()?

Asked by 8 years ago

I don't really understand how to use CFrame:lerp(), can someone explain?

My attempt that doesn't work

part = script.Parent    
startCFrame = part.CFrame 
endCFrame = CFrame.new(-28.8, 0.5, 31.8) 
part.ClickDetector.MouseClick:connect(function()
    for i = 0, 1, 0.1 do 
        part.CFrame = startCFrame:lerp(endCFrame) 
    end
end)

1 answer

Log in to vote
3
Answered by 8 years ago

Linear interpolation

lerp(start, end, alpha) -> start + (end-start)*alpha
For you, this means that you simply need to add i to your Lerp, and make sure you include a wait() so that you can see it happening.

part = script.Parent    
startCFrame = part.CFrame 
endCFrame = CFrame.new(-28.8, 0.5, 31.8) 
part.ClickDetector.MouseClick:connect(function()
    for i = 0, 1, 0.1 do 
        part.CFrame = startCFrame:lerp(endCFrame,i);
    wait();
    end
end)
0
Oh okay, thanks! TheHospitalDev 1134 — 8y
Ad

Answer this question