I've been trying to work out Custom Buoyancy with BodyForce because BodyPosition was giving me troubles.
Anyways, my problem is that my object that is placed in water bobs more and more creating a self perpetuating cycle, until it is thrown by the force.
I think I need some sort of water resistance, but I'm not sure how to go about doing that.
Here is a video of the problem https://imgur.com/a/LxkJ4rD
And here is the code that causes it:
local water = game.Workspace.Water
local waterLevel = water.Position.Y + 0.5*water.Size.Y
local BuoyantPart = script.Parent
local RotatedRegion3 = require(game.Workspace.RotatedRegion3) --Pretty much an intersection detector
local NewRegion3 = RotatedRegion3.FromPart(water)
while wait() do
local waterHeight = water.Position.Y + (water.Size.Y * 0.5)
local topSurfacePosition = BuoyantPart.Position.Y + (BuoyantPart.Size.Y * 0.5)
local PartVolume = BuoyantPart.Size.X * BuoyantPart.Size.Y * BuoyantPart.Size.Z
local BuoyantForce = PartVolume * (BuoyantPart.Size.Y - (topSurfacePosition - waterHeight) + (water.Size.Y/2 + BuoyantPart.Size.Y/2))
--Changes based on how much the object is in the water
if NewRegion3:CastPart(BuoyantPart) then --Returns true if part is in the water
if BuoyantPart:FindFirstChild("BodyForce") == nil then -- Create BodyForce Instance inside of part and start the force
local BodyForce = Instance.new("BodyForce")
BodyForce.Force = Vector3.new(0, BuoyantForce, 0)
BodyForce.Parent = BuoyantPart
elseif BuoyantPart:FindFirstChild("BodyForce") ~= nil then -- Continue exerting force
BuoyantPart.BodyForce.Force = Vector3.new(0, BuoyantForce, 0)
end
else --If part is not in the water stop pushing it
if BuoyantPart:FindFirstChild("BodyForce") ~= nil then
BuoyantPart.BodyForce.Force = Vector3.new(0, 0, 0)
end
end
end
Thank you

2 comments
Maybe you can make the force weak everytime it touch the water (water resistance).
The thing is, the object floats because of the force put onto it, if I were to make it weaker over time, the object would float, then slowly sink