Hello, I have been working on a gerstner wave system for a couple days now. Just got the waves properly generating on the client, and I thought “oh hey lets make something float!” BIG MISTAKE so I made a part, added a script to it for testing and made the script use the same formula the client uses. The formula required a time so I used tick() on both. Then I just had it use the gained Y position from the formula to set the Y position of the object. After all that you’d think it’d be pretty close to following the water on the client?
This is that object, floating very incorrectly compared to the client.
I have no idea why this is happening, here’s the formula (Credit to @Sir_Falstaff for making the formula) I used on both client and server:
function GerstnerWave(SamplePosition,Wavelength,Direction,Steepness,Gravity,SampleTick)
local k = (2 * math.pi) / Wavelength
local a = Steepness/k
local d = Direction.Unit
local c = math.sqrt(Gravity / k)
local f = k * d:Dot(Vector2.new(SamplePosition.X,SamplePosition.Z)) - c * SampleTick
local cosF = math.cos(f)
--Displacement Vectors
local dX = (d.X * (a * cosF))
local dY = a * math.sin(f)
local dZ = ( d.Y * (a * cosF))
return Vector3.new(dX,dY,dZ)
end
RunService.Heartbeat:Connect(function()
local Height1 = GerstnerWave(script.Parent.Position,10.0,Vector2.new(0,1),5.0,2.0,tick()).Y
local Height2 = GerstnerWave(script.Parent.Position,10.0,Vector2.new(1,0),5.0,2.0,tick()+1).Y
local NewHeight = (Height1/2)+(Height2/2)
script.Parent.Position = Vector3.new(script.Parent.Position.X,NewHeight,script.Parent.Position.Z)
end)
*Is the server version, but the client is the exact same math.
and also on the client I used the world position of the bones not just their position. Which means these should be synced up?
Someone please tell me what I’m messing up here, I even tried sampling four points around it, still didn’t work.