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

How to prevent part moved by lerp() from slowing down?

Asked by
zor_os 70
6 years ago
Edited 6 years ago

So i'm trying to learn how to use lerp to have a part move to a certain location but the closer it gets the slower it gets and I want to know if there's a way to prevent that.

Script

game:GetService("RunService").Heartbeat:Connect(function(step)
    local position = script.Parent.dest.Value
    local speed = 5
    local list = workspace.MoveAreas:GetChildren()
    for i = 1,#list do
        if list[i].Position == position then
            script.Parent.CFrame = script.Parent.CFrame:lerp(list[i].CFrame,step/speed)
        end
    end
end)
1
You're lerping using the CURRENT CFrame. This means as the distance to the destination becomes smaller, lerp, being a fraction of a smaller value, also moves a smaller distance. Lerp it as a constantly increasing fraction/percent of the INITIAL CFrame, not the running current CFrame. Cousin_Potato 129 — 6y
0
I figured that but I tried using script.Parent.CFrame = Cf.CFrame:lerp(list[i].CFrame,step/speed) (cf is the cframe of its initial position) and it doesn't move at all. zor_os 70 — 6y
0
Never mind figured out my problem was I was just using 0.1 as a test so that's why it didn't move, Thanks Cousin_Potato zor_os 70 — 6y

Answer this question