Weird drifting problem with boats

So I made a simple boat but I get this weird drifting problem…

local Seat = script.Parent.CaptainSeat

Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	local Char = Seat.Occupant.Parent
	local plr = game:GetService('Players'):GetPlayerFromCharacter(Char)
	if tostring(game.Players:GetPlayerFromCharacter(Seat.Occupant.Parent).UserId) == tostring(script.Parent:WaitForChild("Owner").Value) then
		game.ReplicatedStorage:WaitForChild('ClientEvents').ChangeCamera:FireClient(plr, Seat.Parent)
	end
end)

Seat.Changed:Connect(function()
	script.AngularVelocity.AngularVelocity = Vector3.new(0,-1 * Seat.Steer,0)
	script.LinearVelocity.LineVelocity = script.Parent:WaitForChild("Statistics").Speed.Value * Seat.Throttle
end)

Topic similar to: Boat is drifting forward when steered (Not resolved)

AlignOrientation:

LinearVelocity:

AngularVelocity:

maybe keep track of position in the script and then use an alignposition

That sounds like a good idea but how would I do that tho?

Allign position stays relative to a attachment when you rotate obviously instead of world axis.

AlignPosition.Position = boatPosition + velocity
where your velocity would be
script.Parent:WaitForChild("Statistics").Speed.Value * Seat.Throttle

1 Like

So I did this and I get this error:

BoatController:13: attempt to perform arithmetic (add) on Vector3 and number

For this line of code:

script.Parent.AlignPosition.Position = Seat.Parent.Position + script.Parent:WaitForChild("Statistics").Speed.Value * Seat.Throttle

Is script.Parent:WaitForChild("Statistics").Speed.Value a number? If so, you can’t add a Vector3 with a number. It causes an arithmetic error.

script.Parent:WaitForChild("Statistics").Speed.Value * Seat.Throttle

should be

(script.Parent:WaitForChild("Statistics").Speed.Value * Seat.Throttle * Seat.CFrame.LookVector)

or the lookvector of the boat if that works better

Its still drifting somehow tho.

try increasing force or responsiveness of the alignorientation so it rotates faster

Even when the responsiveness is at max, it still drifts.

oh i just realized you have both alignorientation and angularvelocity which are probably fighting each other

you can do the same thing and get rid of the angular velocity then keep track of the angle in the script and then set the AlignOrientation to Vector3.new(0,angle,0)

I have done this now but I can’t turn at all.

Seat.Changed:Connect(function()
	script.Parent.AlignPosition.Position = Seat.Parent.Position + (script.Parent:WaitForChild("Statistics").Speed.Value * Seat.Throttle * Seat.CFrame.LookVector)
	--script.AngularVelocity.AngularVelocity = Vector3.new(0,-1 * Seat.Steer,0)
	script.LinearVelocity.LineVelocity = script.Parent:WaitForChild("Statistics").Speed.Value * Seat.Throttle
end)