Custom Water made out of Wedges

roblox water

I might use this for a hangout game in the middle of the ocean or something. What do you guys think?

36 Likes

I love it. Will you make the code open source?

3 Likes

Thanks.
I probably won’t make it open source, but if you’re interested in making it yourself, I could give you some pointers.

3 Likes

I think it is wonderful! You must have a great imagination! Keep up the hard work. I would rate this 9/10! I would make the color a little lighter.

2 Likes

Thanks a lot. I just made the water dark because I wanted to recreate the dark waters of the Northern Atlantic.

1 Like

Indeed, I was wondering the reason. Keep up the good work!

1 Like

Yes, I would like to make for myself too.

What math did you use to make this? I have similarly seen terrain made with triangles.

This is nice work.

1 Like

Well, the first thing you’d have to tackle is filling in the space between 4 vertices in a square. The way I approached this was creating a wedge and positioning it so that its hypotenuse runs from one vertex to another vertex. Then to get it rotated and sized properly, it takes a bit of trigonometry. Once you can successfully fill in a 1x1 square, make a 2d array (10x10) or so, and set the heights with a function like sine. If you wanted to animate, you just have to update the wedges each step (or less if you want to avoid lag).

5 Likes

It’s mostly just working with trigonometry and vectors.

2 Likes

By the way, I used 4 wedges per 4 vertices.

3 Likes

I understand filling in the 4 vertices and making sure its hypotenuse runs from 2 vertices but not the rest. A trigonometric example would be nice!

Isn’t two wedges enough to fill a square, why four?

1 Like


Hopefully this will help.

The heights of each of those vertices aren’t the same, and sometimes you need to use a triangle that isn’t a right triangle, so to accommodate that, you need to use twice as many wedges because any triangle can be split up into 2 right triangles

1 Like

Ohh I see, also what do you mean by a 10x10 array? I am stumbled on what makes an array dimension times dimension (N x N). Is it just iterating over an array containing 10 values 10 times?

Pretty much. Here’s how I make the array:

local array = table.create(11)
local xbound = 10
local ybound = 10
for xi=1,xbound+1 do
	array[xi] = table.create(11)
	for yi=1,ybound+1 do
		array[xi][yi]= --whatever function you want to use to calculate heights
	end
end

The way you then access the heights is with 2 for loops

for yi=1,ybound do
		for xi=1,xbound do
               local height = array[xi][yi]
               --make triangles
        end
end
5 Likes

Nice creation! This is one of the few more satisfying things I’ve seen. Keep up the good work!

2 Likes

Thank you very much for the compliments!

1 Like

Why add 1 to the table count and goal in the iterator?

Thank you for being generous enough to answer, I hope I am not flooding the replies too much and if so you could do the answers in messages if needed, I just have never set foot into this type of code.

This will be helpful to understand the other generation code I found since it has practically a similar usage.

Don’t worry about it.

I add 1 to the table count because of how I define the vertices when I make the triangles.
I do something like

local v1 = Vector3.new(xi,array[xi][yi],yi)
local v2 = Vector3.new(xi+1,array[xi+1][yi],yi)
local v3 = Vector3.new(xi,array[xi][yi+1],yi+1)
local v4 = Vector3.new(xi+1,array[xi+1][yi+1],yi+1)

Say I looped through this 10 times. Without having an 11x11 array, I’d get an error because I use array[xi+1][yi+1] for the 4th vertex.

4 Likes

Oh, I understand now. Thank you for the explanation! For the sine function, did you use math.sin() and just place a unconstant number that changes Y values (heights?) to create an animation? I do know its used to get Y on an unit circle so this is my guess.

1 Like