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

Vector3 Lerp finishing too early?

Asked by 5 years ago
function moveCrane(route)
    for i = 1, #route do
        for a = 0, 1, 0.005 do
            crane.Position = crane.Position:Lerp(route[i].Position, a)
            wait()
            print(a)
        end
    end
end

I don't see what I'm doing wrong here, I want the block called "crane" to have it's position lerped to the specified one. It works, but not fully. Here's what I mean by that:

The part moves as you would expect from doing this, but, when the part gets to the specified location, 'a' is only at ~0.25 or something like that. To me, 'a' being at 0.25 would mean that the part would be one quarter of the way there, not already there. Maybe I'm doing something wrong. Any help is appreciated.

0
have you tried printing the #route number? there might not be enough for the lerp to finish at that pace SerpentineKing 3885 — 5y
0
i have tried taking the lerp for loop out of the function and the other for loop and manually specifing the goal position, and the same thing happens. wittyusername65 0 — 5y
0
i fixed it, i was being dumb. wittyusername65 0 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

for anyone wondering, i fixed it with this:

function moveCrane(route)
    for i = 1, #route do
        local startPos = crane.Position
        for a = 0, 1, 0.1 do
            crane.Position = startPos:Lerp(route[i].Position, a)
            wait()
            --print(a)
        end
    end
end
Ad

Answer this question