Why does my smooth terrain generator always generate similar terrain?

so right now i have a generator that is supposed to randomly generate terrain but for some reason every time its always up on the for sides and a hole in the center (image below)


script

local X, Z = 100,100

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(2, height, math.abs(ab:Dot(back)));
	w1.CFrame = CFrame.fromMatrix((a + b)/2, right, up, back);
	w1.Parent = workspace.BlockTerrain;

	local w2 = wedge:Clone();
	w2.Size = Vector3.new(2, height, math.abs(ac:Dot(back)));
	w2.CFrame = CFrame.fromMatrix((a + c)/2, -right, up, -back);
	w2.Parent = workspace.BlockTerrain;

	return w1, w2;
end

local positionGrid = {}
local count = 0
local seed = math.random(70,500)
for x = 0, X do
	positionGrid[x] = {}
	for z = 0, Z do
		seed = math.random(70,500)
		print(x)
		print(z)
		positionGrid[x][z] = Vector3.new(x*20, math.noise(x/50, z/50) * seed, z*20)
	end
end

for x = 0, X-1 do
	for z = 0, Z-1 do
		local a = positionGrid[x][z]
		local b = positionGrid[x+1][z]
		local c = positionGrid[x][z+1]
		local d = positionGrid[x+1][z+1]

		draw3dTriangle(a, b, c)
		draw3dTriangle(b, c, d)
	end
end
for i,v in pairs(game.Workspace.BlockTerrain:GetChildren()) do
	local s= v.Size
	if v.Name == "Water" then
		workspace.Terrain:FillBlock(v.CFrame,s,Enum.Material.Water)
		v:Destroy()
	end
end
for i,v in pairs(game.Workspace.BlockTerrain:GetChildren()) do
	local s= v.Size+Vector3.new(20,0,0)
	if v.Position.Y < -20 then
			workspace.Terrain:FillBlock(v.CFrame,s,Enum.Material.Sand)
			v:Destroy()
	elseif v.Position.Y > -20 and v.Position.Y < 15 then
		local terraintype = math.random(1,15)
		if terraintype == 1 then
			workspace.Terrain:FillBlock(v.CFrame,s,Enum.Material.Mud)
			v:Destroy()
		elseif terraintype == 2 then
			workspace.Terrain:FillBlock(v.CFrame,s,Enum.Material.LeafyGrass)
			v:Destroy()
		else
			workspace.Terrain:FillBlock(v.CFrame,s,Enum.Material.Grass)
			v:Destroy()
		end
	else
		local terraintype = math.random(1,10)
		if terraintype == 1 then
			workspace.Terrain:FillBlock(v.CFrame,s,Enum.Material.Rock)
			v:Destroy()
		else
			workspace.Terrain:FillBlock(v.CFrame,s,Enum.Material.Snow)
			v:Destroy()
		end
	end
end

is there any way i can make this stop happeneing?

Perhaps the random seed is being cached, try testing ingame.

that is in me testing it in game

Have you tried using math.randomseed()

1 Like

When i print seed it is a random number each time.

I think what he’s saying is you should try setting math.randomseed at the start of your script, like so:

math.randomseed(tick())

You can also use this seed in your noise function.
local seed = tick()
math.randomseed(seed)

– three hours later

math.noise(x/50, y/50, seed)

After adding this my game becomes SUPER LAGGY and also the terrain dosent even show