How can i make my boat work?

local moveVectors = {
    ["Left"] = true, 
    ["Right"] = true,
    ["Front"] = true,
    ["Back"] = true,
}

local function checkVectors()
    for i,v in pairs(moveVectors) do
        local ray = Ray.new(Boat.PrimaryPart.CFrame.p, (i == "Left" and Boat.PrimaryPart.CFrame.rightVector * -2) or (i == "Right" and Boat.PrimaryPart.CFrame.rightVector * 2) or (i == "Front" and Boat.PrimaryPart.CFrame.lookVector * 2) or Boat.PrimaryPart.CFrame.lookVector * -2)
        local hit, hitPos, material = workspace:FindPartOnRayWithIgnoreList(ray, {Boat})
        if hit or hitPos or material then
             moveVectors[i] = false
        else
             moveVectors[i] = true
        end
    end
end

-- calling it in your heartbeat function 
game:GetService("RunService").Heartbeat:Connect(function()
     checkVectors()
     if (TValue > 0 and moveVectors["Front"]) or (TValue < 0 and moveVectors["Back"]) then
         Engine.Force = Vector3.new(0, 0, speed * TValue)
     else
         Engine.Force = Vector3.new();
     end
     if (SValue > 0 and moveVectors["Left"]) or (SValue < 0 and moveVectors["Right"]) then
         SForce.CFrame = DSeat.CFrame * CFrame.fromEulerAnglesXYZ(0, math.rad(RotateSpeed * -SValue), 0)
    else
         SForce.CFrame = DSeat.CFrame
    end
end)
4 Likes

doesn’t seem to be working for part terrain
ill check it on normal terrain

1 Like

Alright, it should have worked, are you getting any errors?

1 Like

not currently. ill try it with terrain now

1 Like

Can you take a picture of your boat with the primary part selected because depending on the size of the primary part you may need to change the size of the ray cast.

1 Like

here:

1 Like

i am in my testing area rn because my map is secret :wink:
also, any idea why my camera script for it isnt working?

game:GetService("RunService").RenderStepped:Connect(function()
    if script.Parent.Occupant == game.Players.LocalPlayer.Character.Humanoid then
	    workspace.CurrentCamera.CFrame = script.Parent.Parent.Camera.CFrame
    end
end)
1 Like

Adjust the size of the ray casting then try again, and make sure to set the CurrentCamera type to Scriptable.

1 Like

ok, the boat stops when on land now but when you turn at the same time it can move

1 Like

So what you’re telling me is you can’t go forward and turn at the same time?

1 Like

you can turn and go forwards but this happens when on land: https://gyazo.com/2273e8e34cbcd7a61e1c1ddc307c8af3
i can turn to make it move on land as turning is still working on land

You may want to add a ray cast straight down and check if the material is water if not then kill the engine

ok, i have done this and it works 100% ty

(which post should i mark as the solution?)

Honestly doesn’t matter to me, which ever one helped you the most.

just found a problem, the boat has a spinning seizure when i get on it https://gyazo.com/6a30b6b4f0dd0e1b59b7650f9be264de

You could always try setting SValue and TValue to 0; when someone sits in the seat. As well as anchor the primary part to begin with; then let the script change the anchored property.

DSeat:GetPropertyChangedSignal("Occupant"):Connect(function()
    SValue = 0;
    TValue = 0;
    if DSeat.Occupant then
         Boat.PrimaryPart.Anchored = false
    else
         Boat.PrimaryPart.Anchored = true
    end
end)

ill give that a try. the problem occurred when the player got in the boat and when they get out it stops but if they get back in it continues

ok, so my boat is still having a carousel moment

Sorry about the late reply. Could you upload your test place so I could fool around with the script really quick so I can help you fix this issue?

sure, i will just give you the model as it is easier