Hey there! Currently working on my game! I’ve taken inspiration from Deepwoken’s boats which are amazing! I’ve been trying to get my boat to work, but it seems it doesn’t want to cooperate.
Here is my Module script aswell as my Boat script.
Code
-- Boat module
local boat = {}
function boat:start(part)
self.part = part
self.part.BodyPosition.Position = Vector3.new(0, 0, 0)
self.part.BodyPosition.MaxForce = Vector3.new(0,math.huge,0)
self.part.BodyVelocity.Velocity = Vector3.new(0, 0, 0)
self.part.BodyGyro.cframe = CFrame.new(math.huge, 0, math.huge)
self.part.BodyGyro.maxTorque = Vector3.new(math.huge, 0, math.huge)
self.part.BodyGyro.P = 11000
self.part.BodyGyro.D = 10
self.speed = 0
end
function boat:move(speed)
local direction = self.part.CFrame.lookVector
self.part.BodyVelocity.Velocity = direction * speed
end
function boat:rotate(axis, angle)
local currentangle = 0
self.part.BodyGyro.cframe = self.part.BodyGyro.cframe * CFrame.Angles(0, currentangle + angle, 0)
end
function boat:rotateAtSpeed(speed)
self.part.BodyAngularVelocity.angularvelocity = Vector3.new(0, speed, 0)
end
return boat
local boatModule = require(game.ServerScriptService.ModuleScript)
local boat = boatModule:start(script.Parent)
local seat = script.Parent.VehicleSeat
local steerangle = 0
local speed = 0
local depthbefore = 1
local displacementamount = 4
local function OnChange(property)
if property == "Steer" then
if steerangle <= 10 and steerangle >= -10 then
if seat.Steer > 0 and steerangle > -10 then
steerangle -= 1
print(steerangle)
boatModule:rotateAtSpeed(steerangle * 0.01)
elseif seat.Steer < 0 and steerangle < 10 then
steerangle += 1
print(steerangle)
boatModule:rotateAtSpeed(steerangle * 0.01)
end
end
elseif property == "Throttle" then
if speed <= 10 and speed >= -1 then
if seat.Throttle > 0 and speed < 10 then
speed += 1
elseif seat.Throttle < 0 and speed > -1 then
speed -= 1
end
end
end
end
seat.Changed:Connect(OnChange)
while wait() do
boatModule:move(speed)
end
Boat.rbxl (105.7 KB)
If you could give me any help that would be appreciated. I’m happy to redo my code I just need guidance in where.
Thank you in advanced.