Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
11

How do I get the height of a wave? [closed]

Asked by
Xiousa 156
7 years ago
Edited 7 years ago

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

2
wow much math Perci1 4988 — 7y
0
might need someone smart to post an answer unmiss 337 — 7y
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? honeygold13843 136 — 7y
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. BlackJPI 2658 — 7y
View all comments (11 more)
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. honeygold13843 136 — 7y
0
X and Z are not positions. The values are 0, and they are not related to position. Xiousa 156 — 7y
0
It may have seemed that way with the way I had the code set up. Xiousa 156 — 7y
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. Xiousa 156 — 7y
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. Xiousa 156 — 7y
0
Is the wave height set to 1? script_help 74 — 7y
0
Yes @script_help. Xiousa 156 — 7y
0
Did you try using rays? Might sound stupid but it can help. superalp1111 662 — 7y
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 :) superalp1111 662 — 7y
0
Actually, rays think of water as just a solid square; the waves aren't part of the hitbox. Xiousa 156 — 7y
0
idk, the script looks like right gloveshun 119 — 5y

Locked by JesseSong

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

1 answer

Log in to vote
0
Answered by 7 years ago

print((Part.Position))

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

im very positive it is this

0
No, because the hitbox of the water is a flat plane; the hitbox never changes, even though the rendered water does. Xiousa 156 — 7y
Ad