Heya! So, I am working on a custom water physics engine, but I’ve run into a problem. Basically, I seem to not be able to get precise enough mass measurements for the player to fully cancel out gravity. Is there any way to completely stop the player from sinking without changing the workspace gravity, or do I just have to live with the player slowly sinking?
You can see that the player starts from the spawnpoint, and there was no force pushing them downwards, but they are still sinking.
Code:
task.wait()
local RS = game:GetService("RunService")
local character = game:GetService("Players").LocalPlayer.Character or game:GetService("Players").LocalPlayer.CharacterAdded:Wait()
local water = game.Workspace.Water
local hrp = character:WaitForChild("HumanoidRootPart")
local function getPlayerMass()
local playerMass = 0
for i, v in pairs(character:GetDescendants()) do
task.wait()
if v:IsA("BasePart") or v:IsA("MeshPart") == true then
if not v.Massless then
playerMass += v.Mass
end
end
end
return playerMass
end
print(getPlayerMass())
local playerMass = getPlayerMass()
local att = Instance.new("Attachment")
att.WorldPosition = hrp.Position
att.Name = ("SwimmingATT")
att.Parent = hrp
local function antiGrav()
local force = Instance.new("VectorForce")
force.RelativeTo = Enum.ActuatorRelativeTo.World
force.Force = Vector3.new(0, workspace.Gravity * playerMass, 0)
force.ApplyAtCenterOfMass = true
force.Attachment0 = att
force.Name = ("SwimmingForce")
force.Parent = hrp
force.Enabled = false --(For now)
RS.Heartbeat:Connect(function()
force.Enabled = true
end)
end
task.wait(1)
print("Triggering func")
antiGrav()