Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I get the height of a wave?

Hey, I've been working on boat physics, and I was experimenting with smooth terrain water.

It was going great...

...until the water was going over the raft, and making it look unrealistic.

local x, z = 0, 0
game:GetService("RunService").RenderStepped:connect(function()
	y = 1.8 * math.sin((math.pi * 2) / 85 * x * game.Workspace.Terrain.WaterWaveSpeed / 10) * math.sin((math.pi * 2) / 85 * z * game.Workspace.Terrain.WaterWaveSpeed / 10) + 15
	x = x + 0.18
	z = z + 0.18
	script.Parent.Position = Vector3.new(0, y, 0)
end)

I've tried that, but it never seems to correctly float; it's either too fast or too slow. The original tweet I got this from is this

15 comments

2

wow much math

0

might need someone smart to post an answer

0

Would you elaborate on what you mean by too fast or too slow? How much faster or slower is it compared to the actual waves?

0

Not sold on this formula. Everywhere x%85 = 0, the water wave height does not change but this equation does not account for this. Also the wave height should be dependent on time, not (x, z) coordinates. This is likely an approximation that works with values close to 0 but not points much further away. Nonetheless, quite a tricky problem without knowing the actual implementation.

0

The wave height is dependent on time since x and z are dependent on time. And y(x, z) in all locations is also changing constantly with time. I think the problem is syncing, assuming the tweet Firefaul linked is correct.

0

X and Z are not positions. The values are 0, and they are not related to position.

0

It may have seemed that way with the way I had the code set up.

0

Also, if I just had it as time alone, and did nothing with the position, that would still mess it up, because the raft would be moving.

0

And yes, @honeygold13843, the problem is syncing the bobbing to the waves themselves; it's always ahead or behind, no matter how I change it.

0

Is the wave height set to 1?

0

Yes @script_help.

0

Did you try using rays? Might sound stupid but it can help.

0

Adding rays front, back and sides of boat(To every corner) to infront of parts can give you position of next wave and get wave's size under your ship. Takes long time, sounds stupid, looks ugly, but can handle your problem :)

0

Actually, rays think of water as just a solid square; the waves aren't part of the hitbox.

0

idk, the script looks like right

1 answer

print((Part.Position))

look at the middle number and thats the height of the wave

im very positive it is this

1 comment

0

No, because the hitbox of the water is a flat plane; the hitbox never changes, even though the rendered water does.

This discussion is preserved as it was. New answers, comments, and votes are closed.