Boat and Velocity

Howdy!

Could someone explain to me why my boat doesn’t go in the direction of steering?

local boat = script.Parent
local vehicleSeat = boat.VehicleSeat

local angularVelocity = vehicleSeat.AngularVelocity
local vectorForce = vehicleSeat.VectorForce

local moveDirection = Vector3.new(0, 0, 1)

vehicleSeat:GetPropertyChangedSignal('ThrottleFloat'):Connect(function()
	vectorForce.Force = moveDirection * vehicleSeat.ThrottleFloat * vehicleSeat.MaxSpeed * vehicleSeat.AssemblyMass
end)


local steerDirection = Vector3.new(-1, 0, 0)

vehicleSeat:GetPropertyChangedSignal('SteerFloat'):Connect(function()
	angularVelocity.AngularVelocity = steerDirection * vehicleSeat.SteerFloat * vehicleSeat.TurnSpeed * vehicleSeat.AssemblyMass
end)

image

1 Like

I cant seem to get the planar attachments to keep the boat level with the horizon, but just looking at it, it appears that the vector force does not rotate with the angular velocity. I.e. the vector force does not depend upon the rotation of the craft.

This is still speculation, will do more research.

If you accelerate after turning, do you then go in the direction that you turned? Or do you go faster in the original direction?

If true then everything is working as intended (according to my recreation of this). But It does seem you need a force to push you in the direction you turn in order to simulate turning on a real boat. How this works using linear velocities is that you turn the velocity, and then your craft goes in the direction the velocity is facing.

Since you are using forces, an object in motion will stay in motion unless acted upon by a different force. In your case you need to add a force to accelerate you until you go into the direction that you turned, How strong, long, and the direction in which the force will go is complicated.

I think it will be easier to use linear velocity in your case, but it depends on what you really want.

It’s because you have to constantly update it. Even though you used get property changed signal just doesn’t work that way.

Put it in a loop instead.

Yes, if you accelerate after turning, you will then begin to go in the new direction. I switched to a LinearVelocity force and am experiencing the same issue. I prefer to have the boat go in the direction you are looking/steering towards. I assumed I am messing up the math?

Honestly I just want a simple boat system. Should I not use forces and maybe just use the “AssemblyLinearVelocity/ApplyImpulse” features of the part instead?

Hmm, Using assemblyLinearVelocity will work if you use some hunky-dory speed multiplied by the direction of travel thing. Which Is possible, if strange. I am not so sure why the velocity did not work, Did you make sure that the Direction of velocity changed when you turned? It might be worth it to first get the direction of travel in a unit vector. You might be able to get that through the orientation of the base part.

I am not so experienced in vehicles and constraints, But you should be able to just have a speed value that changes in response to your input and then multiply that by your unit vector, then set that to the assemblylinearvelocity, or any velocity for that matter, if they work the same.

You’re not messing up the math. Just put it in a loop.
Example:

while true do
   force = force
   turn = turn
   task.wait()
end

While true do loops are probably not the best, but that’s another question for another day.

AngularVelocity has a “RelativeTo” property which if not set carefully might be causing the boat to rotate incorrectly. The AlignOrientation might also be causing problems so try disabling it and see if the boat rotates correctly

have you tried setting the vectorforce’s relativeto a specific attachment that has the same orientation as the boat at the center of it

Did you ever fix it? I’m attempting to do the same thing and I’ve also have my physics set up like you

i found a free model boat that works simalair to what you want, the loops arent optimal but maybe this can help you solve your problem

image



script.Parent.MaxSpeed = script.Parent.Settings.MaxSpeed.Value
maxspeed = script.Parent.MaxSpeed
script.Parent.BodyPosition.position = script.Parent.Position
script.Parent.BodyGyro.cframe = script.Parent.CFrame

value1 = 0

while true do

wait()

if script.Parent.Throttle == 1 then
	
	if value1 < maxspeed then value1 = value1 + script.Parent.Settings.Acceleration.Value end
		
		script.Parent.Driving.Value = true
		
		script.Parent.BodyVelocity.velocity = script.Parent.CFrame.lookVector*value1
		
		script.Parent.Left.Value = false
		
		script.Parent.Right.Value = false
end

if script.Parent.Throttle == 0 then 
	
	script.Parent.Driving.Value = false
	
	script.Parent.BodyVelocity.velocity = script.Parent.CFrame.lookVector*value1
	
	script.Parent.Left.Value = false
	
	script.Parent.Right.Value = false
	
end

if script.Parent.Throttle == -1 then

	if value1 > - maxspeed then value1 = value1 -script.Parent.Settings.Acceleration.Value end
		
		script.Parent.Driving.Value = true
		
		script.Parent.BodyVelocity.velocity = script.Parent.CFrame.lookVector*value1
		
		script.Parent.Left.Value = false
		
		script.Parent.Right.Value = false
		
end

if script.Parent.Steer == 1 then
	
	script.Parent.BodyGyro.cframe = script.Parent.BodyGyro.cframe * CFrame.fromEulerAnglesXYZ(0,- script.Parent.Settings.TurnSpeed.Value,0)
	
	script.Parent.Driving.Value = true
	
	script.Parent.Right.Value = true
	
	script.Parent.Left.Value = false
	
end

if script.Parent.Steer == -1 then
	
	
	script.Parent.BodyGyro.cframe = script.Parent.BodyGyro.cframe * CFrame.fromEulerAnglesXYZ(0,script.Parent.Settings.TurnSpeed.Value,0)
	
	script.Parent.Driving.Value = true
	
	script.Parent.Left.Value = true
	
	script.Parent.Right.Value = false
	
end
end

HI, what is the link to the model ?

Thanks

1 Like