Realistic Oceans Using Mesh Deformation!

Must admit, this is a fantastic release.

Just one thing - As multiple Ocean parts don’t render unless required to do so; they’re sometimes unmatched from the previous wave segment, create a somewhat gap? Is there any advice on how I can fix this?

Sorry for a late response, I somehow missed this. What do you mean by this? Do you mean the line between each waves or the fact that wave planes abruptly stop when far enough away making it look weird when next to active wave planes?

If you meant it looking weird when besides active waves, then a good solution would be to delete the system and edit the module. You can multiply each bone’s wave height by a number signifying how far the bone is by the camera. For example: (in pseudo code)

local dropPerStud = 0.01 — how much the wave height should drop each stud

local newBoneHeight = oldBoneHeight - (distFromCamera * dropPerStud * Math.sign(oldBoneHeight)) 

This would make it so the farmer bones are form the camera, the smaller the
wave actually is. This is useful to make seemless transitions between dead (inactive) waves and real ones. This would make it so the waves far away transition well into dead waves.

To tell if a wave is dead or not, check if the new wave height passes 0. Here is pseudo code:

— Old code
local dropPerStud = 0.01 — how much the wave height should drop each stud

local newBoneHeight = oldBoneHeight - (distFromCamera * dropPerStud * Math.sign(oldBoneHeight)) 

— New Code
local isDeadWave = not (Math.sign(newBoneHeight) == Math.sign(oldBoneHeight))

This would check if the old bone height is on the same side of 0 as the new one.

lol i speak Chinese so i can translate: goodbye! have a good day

1 Like

Regarding your suggestion for laying out the ocean, the lag would be insane (assuming it doesn’t crash). I tried dynamically loading/unloading the ocean plane but due to the # of bones it has a significant lag spike.

Have you tried changing the CFrame to a very far distance and then move it back instead of say, moving it from ReplicatedStorage into workspace? You could use something like partcache. You’ve probably already thought of this, but hey, maybe I helped.

2 Likes

Very good idea, that is a good way to prevent Roblox from doing calculations with the bones. An alternative is this:

If this were to be implemented, it would also do what we need it to do.

2 Likes

Yeah. It makes the part “sleep” afaik, which means nothing happens to it and it acts as if it’s anchored

2 Likes

Yeah I don’t think the rendering system touches it.

1 Like

This is absolutely wonderful, but i’ve been having a few issues with it, it’s probably just me being bad at scripting, but is there a way to have 2 different waves alternate when a event fires, like, in my game have I have a script that fires an event wich triggers a bunch of scripts and starts a storm. when that event is fired, I wanted the waves to become bigger and faster, but I cant seem to get it to work. Thanks in advance

For this, you can use the Wave:UpdateSettings(waveSettings) method (which I actually forgot to document, my bad). You provide a new waveSettings as the only parameter and it will update the wave with the settings. In your case you would just update wave height and maybe frequency. You would update all wave’s wave settings. Hope I helped!

2 Likes

oh yeah, thanks ill go and try it right away.

you may want to add that to the documentation aswell.

2 Likes

How did you get the bones to be all parented to the plane?


The bones from my mesh are like this and I don’t know how to parent them all to the plane without glitching out the mesh.
image
Nvm I solved this.

Blender isn’t totally my thing, so I’m not sure if I would be of much help.

Check out this tutorial here and if you still have the problem, try asking it there.

1 Like

Question, very late

Have you gotten around to make this work completely or not? I´m looking for a solution to bone collission within oceans/seas which are animated

That will be very difficult to do, as Roblox has not added support for collision detection with skinned meshes.

Collision detection isn’t necessarily needed, it can be calculated without it

Theres multiple videos on it just look up “gerstner waves roblox”

Take the object you’d want as a sort of “boyant/boyancy block”

Great tutorial imo, thanks a ton!

2 Likes

I did some research thru APIs and the ¨Skinned MeshParts are live!¨ post and came across this API:

¨ TransformedWorldCFrame¨
Describes the combined CFrame offset of the bone and the current animation offset in world space.

This could help with collision, possibly

Another way I´ve seen before is create triangles on the gerstner waves, which follow the same wave path to detect collision way easier (but more performance impact probably)

Along with that I came across this example:

This is probably the closest we can get to collision detection for skinned meshes, for now.

That’s some good research right there. However, unless there is an official implementation, I don’t plan on updating the module with collisions. I don’t believe it will exactly be performant in real situations, but it’s always worth a shot!

1 Like

Is it possible to detect if a player/camera is inside the water?

2 Likes