# Syncing objects with mesh deformed water

I have the formula for waves and calculating height at any point in the waves too. I can’t get boats on the server to sync up with the waves seen on the clients. Either the boats start flying at some points or get flooded a little.

Alright, give us the secret formula if you please, or like specify what you used to achieve so.

Referenced from this post, I use three different waves with this Gerstner Wave formula to get waves. The SampleTick is on the server and read by the clients to render the ocean but the server can also read it itself to get positions on the server if need-be.

``````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
``````

However, the boat is always off compared to the client, I want to find a way to sync them up to look fluid-ish, I don’t want perfection, I want something that’s presentable, but my current method is anything but.

I think the issue stems from that I’m only using the Y position from that formula when calculating boat position, is there a way that I can calculate the waves constant position at that height? Because it looks normal when I use the X+Z displacement values.

I didn’t add the displacement alongside a stationary sample position when calculating boat position, boats now float perfectly alongside the waves.