How can i make my boat work?

I am trying to make a boat for my game but i do not know what i need to do as i have never worked on vehicles.

i am trying to use BodyAngularVelocity but i cannot control it with a localscript using UserInputService. what should i do?

here is my current progress:
rib.rbxm

also, how would i use BodyVelocity to make the boat go forwards no matter where it is?

6 Likes

worked out how to get it to move forwards, but still can’t steer

local DSeat = script.Parent.Parent.VehicleSeat
local SForce = script.Parent.BodyGyro
local Engine = script.Parent.BodyThrust

speed = 5000
SteerSpeed = 25
local RotateSpeed = 5
local Rotation = 0

DSeat.Changed:Connect(function(p)
    if p == "ThrottleFloat"then
        Engine.Force = Vector3.new(0,0,speed * DSeat.ThrottleFloat)
    end
    if p == "SteerFloat"then
        while DSeat.SteerFloat ~= 0 do
            local deltaTime = wait() 
            SForce.CFrame = SForce.CFrame * CFrame.Angles(0,deltaTime* RotateSpeed * -DSeat.SteerFloat,0)
        end
    end
end)

i am using a global script for this

3 Likes

Personally I don’t like using .Changed

local TValue = 0;
local SValue = 0;
DSeat:GetPropertyChangedSignal("ThrottleFloat"):Connect(function()
    TValue = DSeat.ThrottleFloat;
end)

DSeat:GetPropertyChangedSignal("SteerFloat"):Connect(function()
    SValue = DSeat.SteerFloat;
end)

game:GetService("RunService").Heartbeat:Connect(function()
     Engine.Force = Vector3.new(0, 0, speed * TValue)
     SForce.CFrame = DSeat.CFrame * CFrame.fromEulerAnglesXYZ(0, math.rad(RotateSpeed * -SValue), 0)
end) -- this is just how I'd handle something of the nature. Your equation should have worked tho; maybe you need math.rad(deltaTime * RotateSpeed * DSeat.SteerFloat)
1 Like

ok, thanks. i will test it now

1 Like

If that doesn’t work, would you mind showing me your settings for the BodyGyro.

1 Like

it works but i still need to work out why it wont turn

1 Like

here are my settings for my bodygyro https://gyazo.com/06a635c4eefc23e0515ac0d141fc6460

1 Like

Ah yes, there is an easy fix to this problem then. Your Y value in the torque is set to 0. Try changing that MaxTorque to 0, 1, 0

1 Like

hmm… my steering is inverted

1 Like

Just remove the “-” from DSeat.Value or SValue

1 Like

ok, lets a test. fingers crossed

1 Like

it works. any idea how i can stop it moving on anything other than water?

3 Likes

What does the terrain look like, is it part based or smooth terrain?

1 Like

both, i am using parts for some areas such as a boat landing area and the beach is terrain

1 Like

How about the water, part based or terrain? Because if a primary part of the map is smooth terrain you may want to use RayCasting in the 4 cardinal directions along as downwards; to check for a hitPart, hitPosition and or MaterialType and then compare it to the water if it’s not the water then you’d set your lock function to true and stop the boat from moving.

There are also many things you may want to take into account, say they can’t move forwards because something is blocking the forward path, you may want to look into ways of allowing them to still go backwards. Sometimes a good boat system can get rather complex, rather quick.

1 Like

water is terrain, i cba to make water out of parts. the boat can reverse already

1 Like

and how would i do camera manipulation to a custom camera while driving? i am used to still cameras. would i use render stepped?

1 Like

To make a custom Camera you’d need to use RenderStepped along with Enum.CameraType.Scriptable, if you know the decent cframe for it then it shouldn’t be too bad; just don’t forget to change it back when you to their previous camera settings when they leave the seat.

1 Like

yea, ok. thanks for your help.

1 Like

how would i use raycast to detect terrain? i have only used it in gun frameworks

tried this:

RunService.Heartbeat:Connect(function()
local RayCast = Ray.new(Boat.RayFrom.CFrame.p, (Boat.RayBlock.CFrame.p - Boat.RayFrom.CFrame.p).unit * 100)
    local ignore = {}
    local part, position = workspace:FindPartOnRay(RayCast, ignore, false, true)

    if part ~= "RayBlock" then
	    print("Ray Blocked")
    end
end)

but it didnt work

1 Like