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

Why isn't a part moving properly between two parts with Heartbeat?

Asked by 5 years ago

Hi. I'm using Lerp inside a Heartbeat function to move one part from one point to another. This works perfectly when I'm trying to move the part to only one point, but as soon as it starts moving to a second point, it starts stuttering and stops in the middle where it stutters even more back and forth.

This is probably explained much better in a gif, so here's a link

Here's the code

local RunService = game:GetService("RunService")

local partA = workspace.A --point A
local partB = workspace.B --point B
local partC = workspace.C --moving part

local speed = 2

RunService.Heartbeat:Connect(function(deltaTime)
    local deltaSpeed = deltaTime * speed

    local CFrameLerpA = partC.CFrame:Lerp(partA.CFrame, deltaSpeed)
    partC.CFrame = CFrameLerpA
    wait(5)
    local CFrameLerpB = partC.CFrame:Lerp(partB.CFrame, deltaSpeed)
    partC.CFrame = CFrameLerpB
end)

1 answer

Log in to vote
0
Answered by 5 years ago

After you change PartC's CFrame to CframeLerpB it goes straight into changing the CFrame to CFrameLerpA as it is constantly running that block of code

Consider adding a wait after line 16 "partC.CFrame = CFrameLerpB"

0
Sorry for the late reply. Just tried that, and nothing changed, it still stutters. 987134084 0 — 5y
0
Alright, fixed the problem. Thank you regardless, though. 987134084 0 — 5y
Ad

Answer this question