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

How do I make a canoe move to its boat markers? Also rotating along the way.

Asked by 3 years ago

I already had someone try to help me with this and it wasn't working, here's what I had:

---------------------------------------
--//functions
function StartCanoe()
    script.Parent.PrimaryPart.BodyPosition.MaxForce = Vector3.new(5000, 5000, 5000)
    script.Parent.PrimaryPart.Anchored = false
end

function StopCanoe()
    script.Parent.PrimaryPart.BodyGyro.CFrame = script.Parent.PrimaryPart.CFrame
    script.Parent.PrimaryPart.BodyPosition.Position = script.Parent.PrimaryPart.Position
end

--------------------------------------
--//Main loop

StopCanoe()
wait(1)
StartCanoe()

for i = 1,4 do
    local correctMarker = game.Workspace.BoatMarkers[tostring(i)]
    print("Canoe1 is going to ".. correctMarker.Name)
    script.Parent.Primary:WaitForChild("BodyPosition").Position = correctMarker.Position
    repeat
        wait()
        script.Parent.Primary:WaitForChild("BodyPosition").Position = correctMarker.Position
        script.Parent.PrimaryPart.BodyGyro.CFrame = CFrame.new(script.Parent.PrimaryPart.Position, correctMarker.Position)
    until (script.Parent.PrimaryPart.Position - correctMarker.Position).magnitude <= 30
end
StopCanoe()
script.Parent.PrimaryPart.Anchored = true
wait(180)
StartCanoe()
for i = 5,8 do
    local correctMarker = game.Workspace.BoatMarkers[tostring(i)]
    print("Canoe1 is going to ".. correctMarker.Name)
    script.Parent.Primary:WaitForChild("BodyPosition").Position = correctMarker.Position
    repeat
        wait()
        script.Parent.Primary:WaitForChild("BodyPosition").Position = correctMarker.Position
        script.Parent.PrimaryPart.BodyGyro.CFrame = CFrame.new(script.Parent.PrimaryPart.Position, correctMarker.Position)
    until (script.Parent.PrimaryPart.Position - correctMarker.Position).magnitude <= 30
end

I need the canoe to move to the boat markers that I have, but also rotating so that it isn't just moving plainly. Could someone help me with that? Thanks!

Answer this question