Im trying to help a friend who made a boat and when you get nearby to a wall the boat starts jumping, i don’t really use physics of roblox so idk what is going on
local boat = script.Parent
local base = boat:WaitForChild("Base")
local seat = boat:WaitForChild("VehicleSeat")
local RunService = game:GetService("RunService")
local NOMBRE_LIMITE = "limitedeagua"
local VELOCIDAD_BARCO = 40
local VELOCIDAD_GIRO = 1.5
local DISTANCIA_SENSOR = 6
local FUERZA_EMPUJE = 8000
local AMORTIGUACION = 450
local ALTURA_DESEADA = 1.1
local force = base:WaitForChild("VectorForce")
local vel = base:WaitForChild("LinearVelocity")
local ao = base:WaitForChild("AlignOrientation")
local function obtenerMasaBarco()
local m = 0
for _, p in pairs(boat:GetDescendants()) do
if p:IsA("BasePart") and not p:FindFirstAncestorOfClass("Humanoid") then
m += p:GetMass()
end
end
return math.max(m, 10)
end
local masaFija = obtenerMasaBarco()
force.RelativeTo = Enum.ActuatorRelativeTo.World
force.ApplyAtCenterOfMass = true
ao.RigidityEnabled = false
local anguloGiro = base.Orientation.Y
RunService.Heartbeat:Connect(function(dt)
local limite = workspace:FindFirstChild(NOMBRE_LIMITE)
if not limite then return end
local nivelAgua = limite.Position.Y
local profundidad = nivelAgua - base.Position.Y
if profundidad > -3 then
local fLevante = (profundidad + ALTURA_DESEADA) * FUERZA_EMPUJE
local fAmortiguacion = base.AssemblyLinearVelocity.Y * AMORTIGUACION
force.Force = Vector3.new(0,(masaFija * workspace.Gravity) + (fLevante - fAmortiguacion), 0)
local rayParams = RaycastParams.new()
rayParams.FilterDescendantsInstances = {boat}
rayParams.FilterType = Enum.RaycastFilterType.Exclude
local chocadoDerecha = workspace:Raycast(base.Position, base.CFrame.RightVector * DISTANCIA_SENSOR, rayParams)
local chocadoIzquierda = workspace:Raycast(base.Position, -base.CFrame.RightVector * DISTANCIA_SENSOR, rayParams)
if seat.Occupant then
local objetivoVelocidad = seat.ThrottleFloat * VELOCIDAD_BARCO
if chocadoDerecha or chocadoIzquierda then
vel.MaxForce = 500
ao.MaxTorque = 50000
else
vel.MaxForce = 40000
ao.MaxTorque = 300000
end
vel.VectorVelocity = base.CFrame.LookVector * objetivoVelocidad
-- GIRO
if math.abs(objetivoVelocidad) > 0.5 then
local dir = objetivoVelocidad > 0 and 1 or -1
anguloGiro = anguloGiro - (seat.SteerFloat * VELOCIDAD_GIRO * dir)
end
else
vel.VectorVelocity = Vector3.new(0,0,0)
vel.MaxForce = 5000
end
ao.Enabled = true
ao.CFrame = CFrame.fromEulerAnglesYXZ(0, math.rad(anguloGiro), 0)
else
force.Force = Vector3.new(0, 0, 0)
vel.MaxForce = 0
ao.Enabled = false
end
end)
That jumping has to do with excess force being applied which is resulting in a “on and off” pattern of the force being applied, then turned off, then applied again. This can be solved with a dampening mechanism, which it looks like is already being applied, but the depth calculations seemed backwards based on fluid physics / buoyant forces so I messed with that a little.
I have no way to test if this is effective or not since I don’t have the boats, but the raycast section doesnt seem to alter any of the relevant variables that handles the upwards force, and the turn logic seems fine.
You can try messing with this:
local boat = script.Parent
local base = boat:WaitForChild("Base")
local seat = boat:WaitForChild("VehicleSeat")
local RunService = game:GetService("RunService")
local NAME_LIMIT = "limitdeagua"
local BOAT_VELOCITY = 40
local TURN_VELOCITY = 1.5
local SENSOR_DISTANCE = 6
local PUSH_FORCE = 8000
local DAMPENING = 450
local DESIRED_HEIGHT = 1.1
local force = base:WaitForChild("VectorForce")
local vel = base:WaitForChild("LinearVelocity")
local ao = base:WaitForChild("AlignOrientation")
local function getBoatMass()
local m = 0
for _, p in pairs(boat:GetDescendants()) do
if p:IsA("BasePart") and not p:FindFirstAncestorOfClass("Humanoid") then
m += p:GetMass()
end
end
return math.max(m, 10)
end
local fixedMass = getBoatMass()
force.RelativeTo = Enum.ActuatorRelativeTo.World
force.ApplyAtCenterOfMass = true
ao.RigidityEnabled = false
local turnAngle = base.Orientation.Y
RunService.Heartbeat:Connect(function(dt)
local limit = workspace:FindFirstChild(NAME_LIMIT)
if not limit then return end
local waterLevel = limit.Position.Y
local depth = base.Position.Y - waterLevel -- Swap these so this actually refelcts how deep below the boat is
if depth > -3 then
-- The lower you go, the higher your push force, if above water then no bouyant force
local forceUp = ((depth<0 and -depth or 0) + DESIRED_HEIGHT) * PUSH_FORCE
local forceDampening = base.AssemblyLinearVelocity.Y * DAMPENING
force.Force = Vector3.new(0,(fixedMass * workspace.Gravity) + (forceUp - forceDampening), 0)
local rayParams = RaycastParams.new()
rayParams.FilterDescendantsInstances = {boat}
rayParams.FilterType = Enum.RaycastFilterType.Exclude
local rayResultRight = workspace:Raycast(base.Position, base.CFrame.RightVector * SENSOR_DISTANCE, rayParams)
local rayResultLeft = workspace:Raycast(base.Position, -base.CFrame.RightVector * SENSOR_DISTANCE, rayParams)
if seat.Occupant then
local goalVelocity = seat.ThrottleFloat * BOAT_VELOCITY
if rayResultRight or rayResultLeft then
vel.MaxForce = 500
ao.MaxTorque = 50000
else
vel.MaxForce = 40000
ao.MaxTorque = 300000
end
vel.VectorVelocity = base.CFrame.LookVector * goalVelocity
-- TURN
if math.abs(goalVelocity) > 0.5 then
local dir = goalVelocity > 0 and 1 or -1
turnAngle = turnAngle - (seat.SteerFloat * TURN_VELOCITY * dir)
end
else
vel.VectorVelocity = Vector3.new(0,0,0)
vel.MaxForce = 5000
end
ao.Enabled = true
ao.CFrame = CFrame.fromEulerAnglesYXZ(0, math.rad(turnAngle), 0)
else
force.Force = Vector3.new(0, 0, 0)
vel.MaxForce = 0
ao.Enabled = false
end
end)
The jumping near walls is caused by the LinearVelocity fighting the wall collision. When the boat is blocked horizontally by a wall, Roblox’s physics engine can’t push it forward so it deflects the force upward instead - then the buoyancy VectorForce over-corrects that upward movement, creating the bouncing oscillation.
The issue is that the raycasts only check left and right, not forward, so even hitting a wall head-on keeps MaxForce at 40000 while the constraint keeps trying to push through it. A couple of things to fix:
1 - Add a forward raycast so front collisions also reduce force:
local chocadoFrente = workspace:Raycast(base.Position, base.CFrame.LookVector * DISTANCIA_SENSOR, rayParams)
if chocadoDerecha or chocadoIzquierda or chocadoFrente then
vel.MaxForce = 500
ao.MaxTorque = 50000
else
vel.MaxForce = 40000
ao.MaxTorque = 300000
end
2 - Zero out velocity target when hitting a wall instead of just reducing force:
if chocadoDerecha or chocadoIzquierda or chocadoFrente then
vel.MaxForce = 0
vel.VectorVelocity = Vector3.new(0, 0, 0)
else
vel.MaxForce = 40000
vel.VectorVelocity = base.CFrame.LookVector * objetivoVelocidad
end
Setting MaxForce = 0 completely stops the constraint from fighting the wall, which is what’s redirecting the force upward and causing the jump. The buoyancy will still work fine since that’s handled separately by the VectorForce.