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

How would I slowly orient a brick, given an end rotation?

Asked by 5 years ago
Edited 5 years ago

So I'm making code that smoothly moves an object between waypoints. Each waypoint (a part) contains a number value for its order.

It works fine how it is now (example): https://i.gyazo.com/121dd3371c2b3d749d36beccd43428ec.mp4

However, as you can see in the GIF, the part does not smoothly orient itself to face the next oncoming waypoint.

Here is my code (a Server script whose parent is the red part):

local PathModel = workspace.Path1:GetChildren()

local pathparts = {}

for i = 1, #PathModel do -- Sort the paths
    for i2, v in pairs(PathModel) do
        if v.Order.Value == i then
            table.insert(pathparts, v)
            break
        end
    end
end

--[[ Movement ]]--

for i, v in pairs(pathparts) do
    local seg = CFrame.new(script.Parent.Position, v.Position).lookVector * ((script.Parent.Position - v.Position).magnitude / 20)

    for i = 1, 20 do
        script.Parent.CFrame = CFrame.new(script.Parent.Position + seg)
        wait()
    end
end

Answer this question