local PrimaryPart = script.Parent
local Ship = PrimaryPart.Parent
local SUBMERGED_VOLUME_REQUIRED = 70
local DAMPING_FACTOR = 1.0
local WATER_LEVEL = 5.0
local GRAVITY = game.Workspace.Gravity
if not PrimaryPart:IsA("BasePart") or not Ship:IsA("Model") then
warn("Struktur kapal salah.")
return
end
local TotalMass = 0
for _, part in ipairs(Ship:GetDescendants()) do
if part:IsA("BasePart") and part.Mass > 0 and not part.Massless then
TotalMass = TotalMass + part:GetMass()
end
end
local RequiredBuoyancyForce = TotalMass * GRAVITY
if TotalMass == 0 then
warn("Kapal tidak memiliki massa! Pastikan Massless=false.")
return
end
game:GetService("RunService").Stepped:Connect(function(time, dt)
local CurrentY = PrimaryPart.Position.Y
local Depth = WATER_LEVEL - CurrentY
if Depth > 0 then
local BuoyancyMagnitude = RequiredBuoyancyForce * (Depth / SUBMERGED_VOLUME_REQUIRED)
local BuoyancyForce = Vector3.new(0, BuoyancyMagnitude, 0)
PrimaryPart:ApplyImpulse(BuoyancyForce)
local LinearVelocity = PrimaryPart.AssemblyLinearVelocity
local AngularVelocity = PrimaryPart.AssemblyAngularVelocity
local DragForce = -LinearVelocity * TotalMass * DAMPING_FACTOR * dt
PrimaryPart:ApplyImpulse(DragForce)
local RotationalDrag = -AngularVelocity * TotalMass * DAMPING_FACTOR * dt
PrimaryPart:ApplyAngularImpulse(RotationalDrag)
end
end)
@dark rock