Neutralize buoyancy of player in water

I want to create the most efficient way of negating buoyancy of players in water. This means that a player will not float or sink but remain stationary at the current Y level.

I believe the best way to do this would be to set the density of all player parts to match water (which is
1.0). I have also explored adding up the mass and volume of the player parts to find the density mathematically (density = mass / volume).

I have tried following the information located here.

Here is the code I have written

local Player = game.Players.LocalPlayer
local Character = Player.Character

local equilibrium = 0.935 -- why does 1.0 not work?
local playerMass = 0
local playerVolume = 0
local HeavyProps = PhysicalProperties.new(
	equilibrium, -- density
	0.3, -- friction
	0.5 -- elasticity
)

if not Character or not Character.Parent then
	Character = Player.CharacterAdded:wait()
	while #Character:GetDescendants() < 1 do
		wait()
		print("still waiting")
	end
	for i, v in pairs(Player.Character:GetDescendants()) do
		if ((v:IsA("BasePart") or v:IsA("MeshPart")) and not v.Massless) then
			playerMass += v:GetMass()
			v.CustomPhysicalProperties = HeavyProps
			if not v.Massless then
				local volume = v.Size.X * v.Size.Y *v.Size.Z 
				playerVolume += volume
			end
		end
	end
end
print("Player Mass: " .. playerMass .. " | Player Volume: " .. playerVolume)
print("Density: " .. playerMass/playerVolume)

How can I dynamically set this so any size and shape of player?

1 Like

did you ever figure it out a solution to this problem as I’m trying to solve the same thing.

Wow, that’s an old thread! Unfortunately my idea never made it past the concept phase and I didn’t save the code.