Trying to smooth out Procedural Generation

So I tried to make my procedural or voxel generation more smooth with wedges but it didn’t work.
So I don’t know what to try next.

mapxSize = 128
mapySize = 64
mapzSize = 128

noisescale = 30
amplitude = 20
blockSize = 4

areaAddition = - 288

function Generate(areaNumber, color)
	local seed = math.random(0, 1000000)
	
	areaAddition += 288
	
	for x = 0,mapxSize do
		for z = 0,mapzSize do
			for y = 0,mapySize do
				
				local xPerlin = math.noise(y/noisescale,z/noisescale,seed) * amplitude
				local yPerlin = math.noise(x/noisescale,z/noisescale,seed) * amplitude
				local zPerlin = math.noise(x/noisescale,y/noisescale,seed) * amplitude

				local density = xPerlin + yPerlin + zPerlin + y
				local densityX = xPerlin + yPerlin + zPerlin + x
				local densityZ = xPerlin + yPerlin + zPerlin + z
				if density < 10 and -density < 10 and densityX < 35 and densityZ < 35 and -densityX < 35 and -densityZ < 35 then
					local block = Instance.new("Part", workspace[areaNumber].Generation)
					local blockCheck = Instance.new("Part", workspace[areaNumber].Generation)
					
					block.Name = "Block " .. y
					block.TopSurface = "Smooth"
					blockCheck.Size = Vector3.new(blockSize, blockSize, blockSize)
					blockCheck.Transparency = 1
					
					local randomOrientation = math.random(0,2)
					
					if randomOrientation == 1 then
						block.Orientation = Vector3.new(0,90,0)
						
					else
						
						block.Orientation = Vector3.new(0,-90,0)
					end
					
					block.BottomSurface = "Smooth"
					block.Material = Enum.Material.SmoothPlastic
					block.Anchored = true
					block.Size = Vector3.new(blockSize, blockSize, blockSize)
					block.CFrame = CFrame.new(x*blockSize + areaAddition ,y*blockSize,z*blockSize)
					blockCheck.CFrame = CFrame.new(x*blockSize + areaAddition ,y*blockSize + 4,z*blockSize)
					blockCheck.CanCollide = false
					block.Color = color

					blockCheck.Anchored = true
					
					local wedge = Instance.new("WedgePart", workspace[areaNumber].Generation)
					wedge.Name = block.Name .. "'s Wedge"
					wedge.CFrame = CFrame.new(block.CFrame.X, block.CFrame.Y + 4, block.CFrame.Z)
					wedge.Size = Vector3.new(blockSize, blockSize, blockSize)
					wedge.Anchored = true
					wedge.Orientation = block.Orientation


					wedge.Color = color
					
					blockCheck.Touched:Connect(function(part)
						if part.Name == "Block " .. y - 1 then
							if part:IsA("Part") then
								if part.Parent.ClassName ~= "Model" then
									wedge:Destroy()
								end
							end
						end
					end)
				end
				

			end
		end
		wait()
	end
	
	print(areaAddition)
	
end

Generate(1, Color3.fromRGB(123, 215, 97))

Thanks!

1 Like

One easy thing that should help a bit is change your wait() to task.wait(). You shouldn’t be using wait(). Depending on your dimensions you might even be able to remove the task.wait() altogether or at least do an if to do it less frequently like on a modulo of the X dimension…like only wait every 5 iterations of the X value.

but what about how to make smooth generation

I think to manipulate that many objects you might need to look into using the PartCache module. That way it doesn’t have to keep generating objects over and over and it should smooth things out.

what i mean by smoothing it out is making the land like terrain so you dont have to jump to get up a block

Ah okay…I thought you meant how smooth the generation procedure looked. You might try reducing the size of the blocks. I ditched the wedges and the blockcheck and used a size of 1 and that was pretty easy to climb around on.

You might want to use Terrain since it will automatically smooth it.

so i did that but i find that the island is really small. even when i expand the variables at the top