Realistic Oceans Using Mesh Deformation!

My apologies for the delayed response, you can do this by using this as the time element

workspace:GetServerTimeNow()

1 Like

Sorry for bumping, but does anyone have a way of getting the height of the water at a x y pos?

6 Likes

The post you found is discussing a method for making water appear to float on a mesh in a Roblox game. Hereā€™s a breakdown of what the instructions mean:

Find 4 points: You need to identify four points on the mesh where you want the water to appear. These points should form a shape that can be used as a reference for the waterā€™s position.

Make your point fit inside them: Once you have the four points, you need to ensure that the point representing the water is contained within those points. This step is necessary to ensure that the water is confined to the desired area on the mesh.

Narrow it down to 3: From the four points, you need to select three points in such a way that all three points are on the same side of the triangle formed by those points. This step helps establish a plane on which the water will float.

Use interpolation between those 3 points: Interpolation is a mathematical technique used to estimate values between known data points. In this case, youā€™ll be using interpolation to determine the exact y-coordinate (vertical position) of the waterā€™s surface based on its x and z coordinates (horizontal positions) within the triangle formed by the three selected points.

By following these steps, you should be able to create the effect of water floating on the mesh in your Roblox game.

1 Like

Hey, do you perhaps know why your Gerstner function is returning NaN

Because it is for me, and Iā€™m trying to make floating things with it.

Here is my code:

for _, v in pairs(workspace.Floating:GetChildren()) do
	local transform, point = self:GerstnerPoint(v.Position)
	print(point)
	v.Position = Vector3.new(v.Position.X, point.Y, v.Position.Z)
end

Here is what it is printing:
image

Config:

{
	WaveLength = 50,
	Gravity = 1.5,
	Direction = Vector2.new(0,0),
	FollowPoint = nil,
	Steepness = 0.3,
	TimeModifier = 2,
	MaxDistance = 1500,
}
1 Like

this ended up being exactly what I did and it worked perfectly :pray:

1 Like

No biggie I am super glad I could help you

1 Like

Is there a way we could get this to run on a server script instead of a client?

wouldnā€™t it just put stress on the server and wouldnā€™t be that smooth?

Run visuals on the client, and only some logic to sync clients (just use workspace:GetServerTimeNow()), and float server-owned physics objects on the server.

When you move the waves on the client, you have the added advantage of being able to not animate bones that are to far away. Saving on calculations.

As far as the server is concerned, the sea should just be a flat plane. The server (and client!) can get a wave height approximations by plugging into the gerstner wave formula twice.

1 Like

I wanted to replicate something like this since Iā€™m working on a boat game. ocean ROBLOX [Progress 1] boat and infinite mesh deformation ocean - YouTube

But im lowkey clueless on where to start if I wanted to do this

This resource is definitely a good starting point.
I can also recommend YT-videos, or internet articles about gerstner waves (not necessarily about roblox!).

But be warned that itā€™s a pretty complicated subject.

Once you have a basic working system, the fun starts! Optimization!
The waves should be moved on the client. I found using a custom interpolation method to be much faster than TweenService for moving thousands of bones. As you should limit the amount of calulations every frame.

For boat movement, I found a BodyGyro, BodyPosition and BodyForce to work best for network receive rate. Having 4 forces to tilt the boat is expensive, the bodyGyro can handle tilting. Just get the waveheight at 3 positions, and construct a CFrame that goes through those positions.

1 Like

is there a way to scale this down without ruining the bones or anything else?

Hey, could you give me a code example. Iā€™m honestly confused on how to do that.

2 Likes

anyone still have the model? original one got deleted :frowning:

1 Like

Iā€™ve tried to use this, but it makes remote events lag out the entire client ( I have no idea why). Is there a possible fix for this?

OP seems to have been banned. The assets remain on Roblox though, so you can download it directly here, and change the fileā€™s extension to .rbxm to open it. In case the asset gets removed completely, here are some alternatives:

  • My server, canā€™t guarantee how long Iā€™ll keep it up, but Iā€™ll let you know if I ever remove it
  • Google Drive
2 Likes

This was really helpful for me but i have a problems with it, when i equipping a tool or anything linked to player character causes lagging for game , is there any solution for this?

just wanted to add to this if you reset your character an error occurs with positioning

the way i fixed it was
if not character.PrimaryPart then return end

1 Like