-
What do you want to achieve? Keep it simple and clear!
Buoyancy Effect Using The Buoyancy formula
-
What is the issue? Include screenshots / videos if possible!
I am Pretty Sure the Value of the formula is Correct In My Code But ,
idk How To Apply it correctly ("And This is the Issue ") -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Tried Apply Impulse With Just ValueOfFormula As Argument
and Apply Impulse of Value *DeltaTime
and Even Just using Vector Forces !
and Different RunService Event from pre,post simulation and HeartBeat
Video Showing The Result : Watch Pain To Implement Bouncy Effect | Streamable
function findClosestVertexFromWorldPosition(objectSpacePosition)
local closestVertexId = myEditableMesh:FindClosestVertex(objectSpacePosition)
return closestVertexId
end
local function ReturnVolume(obj:BasePart):number
return obj.Size.X * obj.Size.Y*obj.Size.Z
end
local function RealWorldSpace(LocalSpace:Vector3):CFrame
return MeshPart.CFrame:ToWorldSpace(CFrame.new(LocalSpace * SizeScaler))
end
local function RealLocalSpace (World:CFrame):Vector3
return (MeshPart.CFrame:ToObjectSpace(World)).Position/SizeScaler
end
local DensityOfFluid = 1
game:GetService("RunService").PreSimulation:Connect(function(dt)
local WorldCFrame = HoverPart.CFrame+(-1*Vector3.yAxis*(HoverPart.Size.Y/2))
local objectSpacePositonOfPart = RealLocalSpace(WorldCFrame)
-- Convert World Pos to normalized mesh coordinates
local ClosetVertex = findClosestVertexFromWorldPosition(objectSpacePositonOfPart)
local VertexPos = myEditableMesh:GetPosition(ClosetVertex)
--print(VertexPos,objectSpacePositonOfPart)
local Value =(VertexPos.Y - objectSpacePositonOfPart.Y)*SizeScaler
local FractionOfVolume = (Value/HoverPart.Size.Y)
if FractionOfVolume > 0 then
local buoyancyMag = ( FractionOfVolume * ReturnVolume(HoverPart) ) * workspace.Gravity * DensityOfFluid
local BForce = buoyancyMag*Vector3.yAxis
--print(BForce,"GravityForce : ",HoverPart:GetMass()*workspace.Gravity)
HoverPart:ApplyImpulse(BForce*dt)
end
end)
Note : The Functions used to convert
object to world and vice-versa
is Correct (“tested and visualized”)
and Why i have these Cause i scaled The Editable Mesh
So Pls Do not tell me it`s wrong values from it