VectorForce help

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?



v1fNm6YsR1

1 Like

Why don’t you use BodyPosition? You can just set the Position property of the bodymover and it will tween to that location.

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

3 Likes

when you say “up and down forever” does it still converge close to the target? you could be messy and just use a deadband.

DEADBAND = 0.1

local delta = distanceFromGoal/150
if math.abs(delta) < DEADBAND then
    delta = 0
end
local neededForceMultiplier = 1 + delta

just adjust the constant until it works. I have no idea if 0.1 is even close to accurate.

1 Like

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)

It’s 7:00 minutes in.

I suggest looking towards unity, they already had mesh deformation before roblox and hence Gerstner waves, and so the physics as well.

1 Like

There’s no dampening force of course it won’t…

1 Like

Is dividing the force applied based on distance not the proper dampener?

Thank you, I’ll watch the video

It won’t really work as it’ll still cause infinite oscillations.

I think a sensible thing to do is to read about scripted suspensions in roblox as they use a “dampening force”.

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?

1 Like

bruh this is Java with the Unity Framework. This is Roblox Lua

I’m aware, what is the point you are trying to make? I mentioned I converted it, I am obviously not copying Java and pasting it into Roblox Lua lol.

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

Have you figured out a solution? I’m trying to do essentially the same thing with the same issue…