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

I need help with Lerping a Part to another, help?

So I made a script that moves a Part to another part:

local CFrame1= game.Workspace.StartPart.CFrame
local CFrame2= game.Workspace.EndPart.CFrame
for i= 0,1,.01 do
    game.Workspace.StartPart.CFrame=CFrame1:lerp(CFrame2,i)
    wait()
end

But the problem is it doesn't go all the way to the Ending Part it stops right before the the position I need to it be. And also how would I control the speed of the lerp? (Sorry I'm new to Lerping)

1 answer

✓ Accepted answer

###Problem

Numbers like 0.01 aren't accurately representable in binary, so they are approximated - which can read out to equal more than expected.

What this means for you is that the step .01 is going up by slightly more than expected; subsequently, the for loop ends before it hits the final point.

More info on this topic can be found here, and here.

###Solution

Use whole numbers and divide :D

local CFrame1= workspace.StartPart.CFrame
local CFrame2= workspace.EndPart.CFrame

for i = 0,100,1 do
    workspace.StartPart.CFrame = CFrame1:lerp(CFrame2,i/100)
    wait()
end

1 comment

0

Thank you!

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