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

How do I make this movement continuous?

Asked by 6 years ago

I'm trying to make a part move when the player presses the A key and I want to use linear interpolation to do it, which I'm not very familiar with. The code below moves the part to the desired position but then pauses for a few seconds before it can move again, and I'm not really sure why. How do I make the part move continuously?

function lerp(direction)
    local pos = a.Position + Vector3.new(50,0,0)
    for i = 1,100 do
        if holdingA == true then
            local alpha = i/100
            a.Position = a.Position:Lerp(pos, alpha)
            print(pos)
            wait()
        end
    end
end

uis.InputBegan:connect(function(inputObject)
    if inputObject.KeyCode == Enum.KeyCode.A then
        holdingA = true
        while holdingA do
            lerp()
            wait()
        end
    end
end)

uis.InputEnded:connect(function(inputObject)
    if inputObject.KeyCode == Enum.KeyCode.A then
        holdingA = false
    end
end)
0
since you are waiting in the lerp fuction you do not need a wait on the while loop. you also should break out fo the loops when holdingA is false. User#5423 17 — 6y
0
Your lerp function should be from start to end position. You use a.Position each time which changes store the start position in a variable and use that. User#5423 17 — 6y
0
Thanks so much! Lord_Pear 6 — 6y
0
shouldn't lerp() be called from a.Position.CFrame? DeceptiveCaster 3761 — 6y
View all comments (2 more)
0
just sayin' DeceptiveCaster 3761 — 6y
0
lerp also works for Vector3s abnotaddable 920 — 6y

Answer this question