Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to use CFrame:lerp()?

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

✓ Accepted answer

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)

1 comment

0

Oh okay, thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.