Hello there!, I’m currently making a water wave system, I have no problem with generating the triangles, but the hard part is to make it actually moves. If anyone has any ideas of how I could make it moves and function like a wave, that would be lovely!, as I have absolutely no clue on how to create and where to start such system.
Here’s what my wave made out of triangle looks right now:
And here’s the code for it
local X, Z = 20, 20
local wedge = Instance.new("WedgePart");
wedge.Anchored = true;
wedge.TopSurface = Enum.SurfaceType.Smooth;
wedge.BottomSurface = Enum.SurfaceType.Smooth;
local function draw3dTriangle(a, b, c)
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.parts;
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.parts;
return w1, w2;
end
local posGrid = {}
for x = 0, X do
posGrid[x] = {}
for z = 0, Z do
posGrid[x][z] = Vector3.new(x*5, math.noise(x/10, z/10) * 20, z*5)
end
end
for x = 0, X-1 do
for z = 0, Z-1 do
local a = posGrid[x][z]
local b = posGrid[x+1][z]
local c = posGrid[x][z+1]
local d = posGrid[x+1][z+1]
draw3dTriangle(a, b, c)
draw3dTriangle(b, c, d)
end
end
Thanks!