Custom bouyancy problem

You can write your topic however you want, but you need to answer these questions:

  1. So, I’m making my own custom water, and have successfully got waves working. The biggest problem I have right now is getting my parts to float realistically. I’ve been trying for hours and looked at other posts about the same thing, but I just can’t get it to work.
local WaveModule = require(game:GetService("ReplicatedStorage").WaveModule)
local RunService = game:GetService("RunService")

local OceanTiles = workspace.Tiles:GetChildren()
local floatingObject = workspace.FloatingObject
local vectorForce = nil

local oceanFloorPosition = Vector3.new(0, -60, 0)
local oceanHeight = math.abs((OceanTiles[math.random(1, #OceanTiles)].Plane.Position - oceanFloorPosition).Magnitude)

RunService.Stepped:Connect(function(deltaTime)
	
	local inWater, distance = WaveModule.inWater(floatingObject)
	if inWater then
		local closestBone = WaveModule.getClosesBone(floatingObject, workspace.Tiles.WaterPlane1.Plane)
		
		
		if vectorForce then
			print(10 * math.clamp(distance / oceanHeight - .3, 0, 1))
			vectorForce.Force = Vector3.new(0, floatingObject.PrimaryPart.Mass * workspace.Gravity * (15 * math.clamp(distance / oceanHeight - .3, 0, 1)), 0)
		else
			vectorForce = Instance.new("VectorForce")
			vectorForce.Attachment0 = floatingObject.Base.Attachment
			vectorForce.Parent = floatingObject.Base
			vectorForce.ApplyAtCenterOfMass = true
			vectorForce.RelativeTo = "World"
		end
	else
		if vectorForce then
			vectorForce:Destroy()
			vectorForce = nil
		end
	end
end)

The problems I’ve ran into are either oscillations or that the object just sinks.
Please help me, thanks!

1 Like

So i assume what you want is to have objects float or sink depending on their buoyancy?

couple of things u could test,

check if vector is being added or removed.

Yes :+1:‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎

When the models primaryparts y position is higher than the oceans surface y position, the vectorforce gets removed. When it enters and there already isnt a vectorforce, a new vectorforce gets added


if so then, you’re making a new vector with no force applied to go up when inWater.


if you do have a vector force then it will apply the force to the vector that is already in there.

True, I overlooked that. Is that why it doesn’t work as expected?

could be just add this line

vectorForce.Force = Vector3.new(0, floatingObject.PrimaryPart.Mass * workspace.Gravity * (15 * math.clamp(distance / oceanHeight - .3, 0, 1)), 0)

to this