How to make a smooth boat system!

Hello Roblox! I came here for one reason, the reason is that I need help making a custom Boat System! So that means not using Roblox VehicleSeats!

Unfortunately, I do not have any screenshots, but I can explain what I was trying to do.
So to explain how I would make a boat system is that I would detect key presses and use a linear velocity to react to the key presses so if the key was “W” then, I would change the Z Value of the LinearVelocity!

Well, that’s all from me, thanks for the Help, Byee!

use UserInputService to detect a keyboard input, if the input is KeyCode.W, run a while-loop that increments the LinearVelocity’s Vector3’s Z value up to whatever speed limit you want, breaking the loop when KeyCode.W isn’t pressed anymore. Could do the reverse and decrement the speed when W isn’t held. Look into the function that gets the users’ currently pressed keys and wait until W isn’t in the returned table maybe.

Increment could be something like LinearVelocity.VectorVelocity = LinearVelocity.VectorVelocity + Vector3.new(0,0,1)
and creating a speed limit could be done with math.clamp(z, 0, 100)

1 Like

Ok MP3, what you said was a good idea but, how my boat works is that I check for the key which is held down and then fire a remote event to the server to instantly change the LinearVelocity. Do you think there could be a way to use my way but make it smoother?

Here’s the code

Client.

Client

UserInputService.InputBegan:Connect(function(input)
if input then
if (UserInputService:IsKeyDown(Enum.KeyCode.W)) then
RemoteEvent:FireServer({"moveBoat", "Forward", 1})
end

if (UserInputService:IsKeyDown(Enum.KeyCode.S)) then
RemoteEvent:FireServer({"moveBoat", "Backward", -1})
end

if (UserInputService:IsKeyDown(Enum.KeyCode.A)) then
RemoteEvent:FireServer({"moveBoat", "Left", 1})
end

if (UserInputService:IsKeyDown(Enum.KeyCode.D)) then
RemoteEvent:FireServer({"moveBoat", "Right", -1})
end
end
end)
Server

local Players = game:GetService("Players")

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")


local function moveBoat(boat, dir, num)
if boat and dir then
if dir == "Forward" then
if num == 1 then
local LinearVelocity = boat.PrimaryPart:FindFirstChild("LinearVelocity")

if LinearVelocity then
LinearVelocity.VectorVelocity = (boat.PrimaryPart.CFrame.lookVector * 50)
end
end
end

if dir == "Backward" then
if num == -1 then
local LinearVelocity = boat.PrimaryPart:FindFirstChild("LinearVelocity")

if LinearVelocity then
LinearVelocity.VectorVelocity = -(boat.PrimaryPart.CFrame.lookVector * 50)
end
end
end

if dir == "Left" then
if num == 1 then
local AlignOrientation = boat.PrimaryPart:FindFirstChild("Attachment")

if AlignOrientation then
AlignOrientation.CFrame = CFrame.Angles(math.rad(0), math.rad(1*125), math.rad(0))
end
end
end

if dir == "Right" then
if num == -1 then
local AlignOrientation = boat.PrimaryPart:FindFirstChild("Attachment")

if AlignOrientation then
AlignOrientation.CFrame = CFrame.Angles(math.rad(0), math.rad(-1*125), math.rad(0))
end
end
end
end
end

local function stopMovement(boat)

if boat then
local LinearVelocity = boat.PrimaryPart:FindFirstChild("LinearVelocity")

if LinearVelocity then
LinearVelocity.VectorVelocity = Vector3.new(0,0,0)
end
end
end

RemoteEvent.OnServerEvent:Connect(function(player, tuple)
if tuple then
if tuple[1] == "moveBoat" then
if tuple[2] then
moveBoat(workspace.defaultBoat, tuple[2], tuple[3])
end

if tuple[2] == "StopMovement" then
stopMovement(workspace.defaultBoat)
end
end

end
end)
1 Like

Vector3’s are tweenable, so using this framework, you could try tweening the vector to make it transition between the current and next state rather than be immediate. For example, on your “forward” direction:

local TweenService = game:GetService("TweenService")
--[...]
TweenService:Create(
    LinearVelocity, --instance to be tweened
    TweenInfo.new(1),  --info about the tween (1 being the time to complete)
    {VectorVelocity = (boat.PrimaryPart.CFrame.lookVector * 50)}  --*property* of the instance to be tweened, here, we want to tween LinearVelocity.VectorVelocity
):Play()

Whatever the vector currently is, it will transition over 1 second to the new one. There’s lots of customizability with the TweenInfo parameter to look into too.

2 Likes

Thanks, MP3, just asking, could you help me with steering the boat as am really struggling with it?

for steering u can use an angularvelocity

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.