That’s what it was inspired by. I’m glad it helped you.
this is great! but can you send the Roblox place file to this please?
seems pretty good, most likely will be fun making the formula.
Does this run better than Roblox terrain water?
Thanks for making this. Ive been trying to figure this out for a while now with no luck. I dont want to use terrain water or a simple part water for my builds, because it either looks too flat or too uncanny. Cant wait to try this out later on.
Do you know how performant it is?
yeah if you can use it right, you can make certain areas have larger waves than others though you’ll need to script it.
The performance really depends on how you script it. If your code is really optimized and efficient, it’s better than using terrain water for a big swath of ocean.
Generally, I get spend a lot of time loading and get lag spikes when playing games that use terrain water oceans. With mesh water, though, I scripted a way for the water to be infinite in size and the loading was as though nothing was there. Also had no lag spikes.
I’m by no means a good scripter, so if I can make it work better than terrain water on my machine, I’d say its better.
What code did you use to make it preformat?
I haven’t fully got it working yet, but it seems to perform well. Eventually I’m going to have bones closer towards points of interest and farther away the farther out which should help. Figuring out swimming collisions will be fun.
I am busy rn but you could you use perlin wave formula to make it look like a actual wave and some sine formula looking stuff
Actually, a Gernster is what you are going to want to use for this.
Actually, gerstners provide linear motion unlike actual oceans
But gernsters formula allows for wave crests, unlike a peeling noise formula. Also, Perlin noise is more for land and stuff. So if you are looking to create more realistic waves with actual wave CRESTS, a perlin noise algorithm is not the way to go.
Well if you want crests you could always change your noise density
That wouldn’t make accurate crests, that would just increase the overall height. The whole point of crests are being fo it tie is quickly and crest. Using perlin noise would just make the waves taller, and that’s not what a crest is.
Thanks, super useful to know! I will definitely be using.
A lot of people need some assistance with the wave part, so here:
I’m not too great with scripting, so any direct scripting advice I give will actually probably be a detriment even if it makes your ocean have individual waves.
I can suggest searching “sine wave” in the roblox library and see what some of those use for their formula. You could get some ideas by tinkering with different scripts like I did.
The general idea is that you want to make each bone have a unique Y value. You do this by making the Y value dependent on the bone’s X and Z values if that makes sense.
You can look at this equation for a simple sine wave.
y is the Y value of any point
x is the X value of any point
'a' is the amplitude of the wave. That basically means how high and low the crests and troughs are
'b' is the frequency of the wave. That basically means how close each peak and valley is to each other.
'c' is a modifier similar to "time". You change the C value and the wave moves. (its more complicated but that's essentially how you can look at it)
All you do is place any number you want for x,b,c and you get what y should be.
Since you want to make an ocean out of it, you want y to be constantly moving in a consistent and predictable way.
X will be the X value of the bone (and make room for Z, being the Z value of the bone)
A, the amplitude, will be whatever you want (good for weather conditions)
B, the frequency, will be whatever you want (good for weather conditions)
C will be time. tick() or os.time() works, but again they aren’t synchronized between clients, so different players will see the wave at different times which ruins the look of collisions.
You get the Y value and plug that into the bone’s Y value and you have a waving ocean.
Also bear in mind that this is a basic sine wave formula and not a Gerstner wave formula. I haven’t actually done a gerstner wave formula if you can see in my original finished product gif. If anyone can help me with that, that would be great.
Thanks. I have tried some other formula to create my waves but this one is the superior.
I considered writing my own version of a guide like this, but instead, I’ll just post a few tips:
-
If you are using textures rather than a SurfaceAppearance, you can lock the water plane to the position of the camera and make it appear to move properly by scrolling the UV offset of the texture.
-
Use the same formula that you used to generate the water to detect surface collisions by sampling the wave at the target position rather than trying to detect collisions with the actual wave mesh.
Here is a Gerstner wave function you can use to generate your waves:
--GerstnerWave(Vector3 SamplePosition, Float Wavelength, Vector2 Direction, Float Steepness, Float Gravity, Float SampleTick)
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
-
The wavelength of your smallest wave must be larger than the distance between vertices on your water mesh, otherwise, it will look pretty strange.
-
You can add the displacement from multiple Gerstner waves to get a more convincing final displacement for the water.
OMG IVE BEEN LOOKING FOR SOMETHING LIKE THIS FOR SO LONG!!! Yay