Hello all, so I have a custom water system using a Gerstner wave formula and Bones. Because bones don’t have collisions, I need a way to add custom floating/buoyancy.
Currently this is where I am at:
game:GetService("RunService").Stepped:Connect(function()
local heightGoal = getHeight(Float.WorldPosition,speedCounter).Y + 2 -- Add 2 just so its a little higher in water
local minimumForce = (Float.Parent:GetMass() * workspace.Gravity) / 4 -- Force required to make part weightless devided by 4 (4 attachments per part)
local distanceFromGoal = heightGoal - Float.WorldPosition.Y
local neededForceMultiplyer = 1 + (distanceFromGoal/150) -- 150 was an attempt in dampening the forces
Force.Force = Vector3.new(0, minimumForce * neededForceMultiplyer, 0)
end)
The part kinda bounces up and down forever and never really sets right on the waves like I want. Does anyone have experience with VectorForces and can give me tips on how to make the part sit level on the water’s surface when provided the Y height?
I didnt use BodyMovers because I cannot specify where the force is coming from. The idea of this game is similar to Raft where you can build and expand your raft, thus I need the ability to place buoyancy where necessary and have the ability to apply different forces from different spots.
Even when the raft is only one floating block, I need it to tilt and rock with the waves which you cannot do with a BodyMover without the use of BodyGyro, which brings up its own issues later down the road when I need to physically stimulate the raft running into objects or turning
You will need a drag force to stabilize it. Physics wise it’s like a pendulum in air, without drag it will keep swinging back and forth, but the air resistance causes it to stop.
So far your formula seems similar to the unity one
local neededForceMultiplyer --Based on displacement
local minimumForce -- based on gravity
Force.Force = Vector3.new(0, minimumForce * neededForceMultiplyer, 0)
After watching the video I am stilly slightly clueless. It would seem I need a way of dampening the applied forces. Even when I do a 1:1 conversion of what I see in that video to Lua im still experiencing the same issue. Do you know of a smart way to implement dampening and/or drag?
It seems I have a temporary solution, though im sure it is NOT great for performance. If I set the velocity of the part’s Y axis to Zero before applying the new force each frame then it works properly.
Is there some sort of math I can use to scale the parts force based on its velocity?
If you still need this question answering, let me clear things up for you.
You can practically get the height of the wave by offsetting the original position of the part therefore you can move it to the right position using the Gerstner formula you used for the waves. And if you want to you could increase the resolution of the waves (more bones) to make it more accurate. Also remember to sync the server with the client with tick() or C or else it will never work.
Yes I am doing all of this already. My problem is understanding how strong the force needs to be to move said part to float on the wave. Currently there is no dampening, and the part just flings back and forth, never settling just on the water like I want.
If I set the velocity of the part to Zero at each frame then it works as desired, but doesn’t work properly for parts with multiple floating points. So I somehow need to dampen the force applied to each buoy point based on the parts distance from the goal and it’s current velocity