If you want to make a wave system with math.noise, you should know that it is something deoptimized, I did what you want to do a long time ago: Ocean test
What I did is make a function to generate triangles from 3 points in space:
local wedge = Instance.new("WedgePart")
wedge.Anchored = true
wedge.TopSurface = Enum.SurfaceType.Smooth
wedge.BottomSurface = Enum.SurfaceType.Smooth
wedge.BrickColor = BrickColor.new("Electric blue")
local B = Instance.new("SelectionBox")
B.Parent = wedge
B.Adornee = wedge
local n1,n2,n3 = 0,0,0
local function draw3dTriangle(a, b, c, Color)
local ab, ac, bc = b - a, c - a, c - b
local abd, acd, bcd = ab:Dot(ab), ac:Dot(ac), bc:Dot(bc)
if (abd > acd and abd > bcd) then
c, a = a, c
elseif (acd > bcd and acd > abd) then
a, b = b, a
end
ab, ac, bc = b - a, c - a, c - b
local right = ac:Cross(ab).unit
local up = bc:Cross(right).unit
local back = bc.unit
local height = math.abs(ab:Dot(up))
local w1 = wedge:Clone()
w1.Size = Vector3.new(0, height, math.abs(ab:Dot(back)))
w1.CFrame = CFrame.fromMatrix((a + b)/2, right, up, back)
w1.Parent = workspace.T
local w2 = wedge:Clone();
w2.Size = Vector3.new(0, height, math.abs(ac:Dot(back)))
w2.CFrame = CFrame.fromMatrix((a + c)/2, -right, up, -back)
w2.Parent = workspace.T
end
These triangles I had them put in a folder to make it easier to delete later.
So I put an empty table and started a loop, inside it I started another and inside this other, they will be in charge of putting the positions of the points in the table to later generate the triangles, here, to obtain the Y axis of the points I used the math.noise, its parameters were:
- (First loop + 1 ^ 1.2) / 20
twenty
- (Second loop + 1 ^ 1.2) / 20
In that order and finally to the math.noise I multiply it by 20. And finally, so that all the triangles do not appear at the same point, we are going to order it as follows:
At the point we add a new vector, this vector will have the following formula as the X axis: First loop * 5, for the Y axis we put the noise variable and finally for the Z axis: Second loop * 5:
local Puntos = {}
local n = 1
while true do
for x = 0,X do
Puntos[x] = {}
for z = 0,Z do
local noise = math.noise((x + n ^ 1.2) / 20, 0, (z + n ^ 1.2) /20) * 20
Puntos[x][z] = Vector3.new((x * 5),noise,(z * 5) )
end
end
end
Now we only need to make the points are placed and the triangles are made, for this inside the first loop we are going to put another 2, here we are going to put 4 variables, these are going to be 4 points that now we are going to join by means of the previous triangulation being such that:
for x = 0,X-1 do
for z = 0,Z-1 do
local a = Puntos[x][z]
local b = Puntos[x+1][z]
local c = Puntos[x][z+1]
local d = Puntos[x+1][z+1]
draw3dTriangle(a,b,c)
draw3dTriangle(b,c,d)
end
end
And finally in the loop first we are going to eliminate all the triangles by putting a wait without parameters and we also change the 1 that we use in the math.noise and we add 0.1 to it::
wait()
n = n + .1
workspace.T:ClearAllChildren()
Final code:
local X,Z = 10,10
local wedge = Instance.new("WedgePart")
wedge.Anchored = true
wedge.TopSurface = Enum.SurfaceType.Smooth
wedge.BottomSurface = Enum.SurfaceType.Smooth
wedge.BrickColor = BrickColor.new("Electric blue")
local B = Instance.new("SelectionBox")
B.Parent = wedge
B.Adornee = wedge
local function draw3dTriangle(a, b, c, Color)
local ab, ac, bc = b - a, c - a, c - b
local abd, acd, bcd = ab:Dot(ab), ac:Dot(ac), bc:Dot(bc)
if (abd > acd and abd > bcd) then
c, a = a, c
elseif (acd > bcd and acd > abd) then
a, b = b, a
end
ab, ac, bc = b - a, c - a, c - b
local right = ac:Cross(ab).unit
local up = bc:Cross(right).unit
local back = bc.unit
local height = math.abs(ab:Dot(up))
local w1 = wedge:Clone()
w1.Size = Vector3.new(0, height, math.abs(ab:Dot(back)))
w1.CFrame = CFrame.fromMatrix((a + b)/2, right, up, back)
w1.Parent = workspace.T
local w2 = wedge:Clone();
w2.Size = Vector3.new(0, height, math.abs(ac:Dot(back)))
w2.CFrame = CFrame.fromMatrix((a + c)/2, -right, up, -back)
w2.Parent = workspace.T
end
local Puntos = {}
local n = 1
while true do
local n1,n2 = 40,40
for x = 0,X do
Puntos[x] = {}
for z = 0,Z do
local noise = math.noise((x + n ^ 1.2) / 20, 0, (z + n ^ 1.2) /20) * 20
Puntos[x][z] = Vector3.new((x * 5) + n1,noise + 40,(z * 5) + n2)
end
end
for x = 0,X-1 do
for z = 0,Z-1 do
local a = Puntos[x][z]
local b = Puntos[x+1][z]
local c = Puntos[x][z+1]
local d = Puntos[x+1][z+1]
draw3dTriangle(a,b,c)
draw3dTriangle(b,c,d)
end
end
wait()
n = n + .1
workspace.T:ClearAllChildren()
end```