I found a script from a free model, I made sure to check that it isn’t malicious. It worked on the boat in the free model but when I put the script into my boat that I made, it doesn’t even move.
Script:
local boat = script.Parent
local seat = boat.PrimaryPart
--See: https://www.roblox.com/library/265487607/Cutter
local function GetCenterOfMass(parts)
local TotalMass = 0
local SumOfMasses = Vector3.new(0, 0, 0)
for i = 1, #parts do
local part = parts[i]
TotalMass = TotalMass + part:GetMass()
SumOfMasses = SumOfMasses + part:GetMass() * part.Position
end
return SumOfMasses/TotalMass, TotalMass
end
local function GetBackVector(CFrameValue)
local _, _, _, _, _, r6, _, _, r9, _, _, r12 = CFrameValue:components()
return Vector3.new(r6,r9,r12)
end
local function GetCFrameFromTopBack(CFrameAt, Top, Back)
local Right = Top:Cross(Back)
return CFrame.new(CFrameAt.x, CFrameAt.y, CFrameAt.z, Right.x, Top.x, Back.x, Right.y, Top.y, Back.y,Right.z, Top.z, Back.z)
end
local function GetRotationInXZPlane(cframe)
local Back = GetBackVector(cframe)
return GetCFrameFromTopBack(cframe.p, Vector3.new(0, 1, 0), Vector3.new(Back.x, 0, Back.z).unit)
end
--lonely function
local function getParts(parent)
local parts = {}
local descendants = parent:GetDescendants()
for i = 1, #descendants do
local part = descendants[i]
if part:IsA("BasePart") then
parts[#parts + 1] = part
end
end
return parts
end
--Create attachments and contraints for function
local parts = getParts(boat)
local centerOfMass, totalMass = GetCenterOfMass(parts)
local center = Instance.new("Part")
center.Anchored = true
center.Name = "CenterPart"
center.CanCollide = false
center.Archivable = false
center.Size = Vector3.new()
center.Transparency = 1
center.CFrame = GetRotationInXZPlane(seat.CFrame - seat.CFrame.p) + centerOfMass
center.Parent = boat
local attachment = Instance.new("Attachment")
attachment.CFrame = center.CFrame
attachment.Position = Vector3.new()
attachment.Parent = center
local vectorForce = Instance.new("VectorForce")
vectorForce.ApplyAtCenterOfMass = true
vectorForce.Attachment0 = attachment
vectorForce.Force = Vector3.new()
vectorForce.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
vectorForce.Parent = center
local torque = Instance.new("Torque")
torque.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
torque.Attachment0 = attachment
torque.Torque = Vector3.new()
torque.Parent = center
totalMass = totalMass + center:GetMass()
--Listen for input
seat:GetPropertyChangedSignal("Throttle"):Connect(function()
vectorForce.Force = Vector3.new(seat.Throttle, 0, 0) * 100000
end)
seat:GetPropertyChangedSignal("Steer"):Connect(function()
torque.Torque = Vector3.new(0, -seat.Steer, 0) * 100000
end)
In the free model, it leans to the side when you turn and that’s what I really like about it and also the fact that it worked.
It doesn’t work in my boat model and there are no errors, it just doesn’t move.