Floating Object

Hi, I am wondering what the best system to use would be to have a boat float in this water?

I need it to also to tilt if there is a high part of water at the front of the boat or a low part of water on the left side of the boat, eg.
https://i.gyazo.com/5cb54f7dbde2b653c385ac1e25007edf.gif

Bonus: Does anyone have a nice formula for generating waves? Currently using math.noise

Test Place

2 Likes

If you’re really set on making water that way I’d personally suggest using triangles to connect the points, it makes for a better looking surface with no jagged bumps. As for having boats float on top you may want to cast a ray to find what the elevation of the bow and rear of the ship should be then use bodymovers to achieve the right rotation and such.

4 Likes

Would that not lag with the amount of times the function would need to be called? Also yeah, would love to change it to triangles later down the road.

I should mention also that the boats plan to move and there will be up to about 10 boats in-game at any one time.

You could avoid casting an excess of rays by having the boat remember the tiles under it and updating these tiles once the section of the boat has traveled into the region of a new tile.

1 Like

I used this tutorial to generate some 2D water a while back. I wouldn’t imaging that it would be too hard to convert to 3D. https://gamedevelopment.tutsplus.com/tutorials/creating-dynamic-2d-water-effects-in-unity--gamedev-14143
Instead of making it react to player movement, you could apply an impulse to one side of the water every X seconds to continuously generate waves, or do multiple points (possibly at different intervals) to generate more advanced effects.

Sample:

4 Likes

But the tiles under the boat will be constantly changing too?

Would it be better to get a decent formula for generating waves and then add that formula to the boat with DistributedGameTime?

So you basically have the same formula for generating the waves positions put into the boat to position the boat.

Yeah, you could do that. I’m trying to get back into ROBLOX so I did it as an exercise. The current script doesn’t support any methods of controlling the ship the user, but if you just edit the CFrame the boat’s rotation and height will be adjusted on the next RenderStepped frame. Unfortunately, any rotation the boat has before the next update will not be preserved, but it shouldn’t be too hard to add that functionality. I just need to go to bed right now so I can’t do it :slight_smile:. You could also look into adjusting the positioning so the waves come from a corner instead of one direction, which should just take some trig.

Anyways, I have a sample below, which you can download a copy of (game.StarterPlayer.StarterPlayerScripts.Waves) here: Basic Wave Test - Roblox

Please forgive the weird crops around the edges. I lost all of my super legally downloaded tools.
https://im5.ezgif.com/tmp/ezgif-5-7dbae1e293.gif
P.S. How do you put an image in a [details]?

6 Likes

Wow! That’s amazing, thank you very much :slight_smile:

To put images in details

Details

You either paste it here from clipboard, put link or drag from file directory.

Sine wave is nice but doesn’t have that “realism” feel to it. Any other ideas for how it could be done?

I can’t think of any other equations off the top of my head, aside from the first tutorial I mentioned. You could use that to move the water in a realistic fashion, then position the boat off the points surrounding it. If you store the current water nodes in a 2D array with their position’s as the array’s indexes, you could use modulus on the boat’s position to determine the nodes (if blocks are positioned at 0, 10, 20, 30, 40, …, boat.X % 10) surrounding it. This helps make the script a lot quicker since you don’t need to raycast or use Lua to iterate through anything. Then do some averaging and trig/CFrame-pointing to determine how position and rotate the boat. Just make sure you take into account that the boat is anywhere between the two waves, not directly in the middle, so you can get some nice smooth transitions.

You could also just use ROBLOX’s water.

1 Like

Funny you say that.

I already do:

Problem with Roblox water and boats is that Roblox’s Physics engine gets very slow, very quick.

I use Body Position, Body Velocity etc. Get about 5 ships in-game and they all start to move slow, cannon balls fire very slow. Etc.

1 Like

My friend Siren10 was able to change from math.noise, to this.

Sin * Cos gives a really neat effect.

https://gyazo.com/253e165d9e7ff5f890717272dfc380d0.gif

https://devforum.roblox.com/t/how-to-get-wave-height-at-a-specific-position/30672/5

2 Likes

Thanks for the info!

https://gyazo.com/5436f3c34a4e984e251c46ec5383e4e9.gif