I have a perlin noise generator that is supposed to generate landscapes in my game, it uses egomoose’s triangle generation function to try and generate the terrain.
Upon the script execution, I receive the following terrain.
How would I properly generate landscapes using the noise values that I have?
This is the code that I have for my generator:
local freq = 0.1
local seed = os.clock()
local waterthreshold = 0.3
local mult = 5
local function draw3dTriangle(a, b, c, parent, w1, w2)
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));
w1 = w1 or 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 = parent;
w2 = w2 or edge:Clone();
w2.Size = Vector3.new(0, height, math.abs(ac:Dot(back)));
w2.CFrame = CFrame.fromMatrix((a + c)/2, -right, up, -back);
w2.Parent = parent;
return w1, w2;
end
local last1,last2 = nil,nil
for x = 1,50 do
for y = 1,50 do
print(last1, last2)
local noise = math.clamp(math.noise(((x / mult) + seed) * freq, ((y / mult) + seed) * freq) * mult,0,1 * mult)
if last1 ~= nil and last2 ~= nil then
local w1,w2 = Instance.new("WedgePart"),Instance.new("WedgePart")
w1.Anchored = true
w2.Anchored = true
draw3dTriangle(last1,last2,Vector3.new(x,noise,y),workspace,w1,w2)
end
last2 = last1
last1 = Vector3.new(x,noise,y)
end
end
Any support will be appreciated.
Thank you.