Terrain generation confusion

So ive been making a terrain generator. I know it isnt the right way but i dont understand the right way at all. Can you please give me ideas about how to make terrain generation or how to improve my script?
This is what my really strange looking hills terrain looks like.

Here is the script aswell:

wait(3)
local prevgrassblocklevel = 61
while prevgrassblocklevel % 3 ~= 0 do
	local prevgrassblocklevel = math.random(60,70)
	if prevgrassblocklevel % 3 == 0 then
		break
	end
end

local function CreateChunk(x,z,biome)
	local block = ""
	local maxheight = 69
	if biome == "Plains" then
		maxheight = 60
		block = "GrassBlock"
	elseif biome == "Hills" then
		maxheight = 72
		block = "GrassBlock"
	elseif biome == "Rocks" then
		maxheight = 66
		block = "StoneBlock"
	end

for e = 1,48 do
	if e % 3 == 0 then
		
	for i = 1,48 do
		if i % 3 == 0 then
			local bedrocklevel = CFrame.new(i + x,0,e + z)
			local grasslvlismultiple = false
			local grasslevel
			while grasslvlismultiple == false do
				grasslevel = bedrocklevel * CFrame.new(0,math.random(60,maxheight),0)
				if grasslevel.Y % 3 == 0 and grasslevel.Y - prevgrassblocklevel <= 3 then
					break
				end
				end
				prevgrassblocklevel = grasslevel.Y
			local bedrock = game.ReplicatedStorage.GenerationBlocks.BedRock:Clone()
			local grass = game.ReplicatedStorage.GenerationBlocks:WaitForChild(block):Clone()
			bedrock.Parent = workspace.Blocks
			grass.Parent = workspace.Blocks
			bedrock.CFrame = bedrocklevel
					grass.CFrame = grasslevel
					
					-- fill
					for r = 1,grasslevel.Y - 1 do
						if r % 3 == 0 then
						local fillblock = ""
						local fillblocks = {"StoneBlock"}
							if r >= 54 then
								if biome ~= "Plains" and biome ~= "Hills" then
									fillblock = "StoneBlock"
								else
									fillblock = "DirtBlock"
								end
							else
								fillblock = fillblocks[math.random(1,1)]
							end
							
							local fillblockreal = game.ReplicatedStorage.GenerationBlocks:WaitForChild(fillblock):Clone()
							fillblockreal.Parent = workspace.Blocks
							fillblockreal.CFrame = bedrocklevel * CFrame.new(0,r,0)
							
							
						end
					end
		end
	end
	end
	end
	
end

It actually works well but i just dont like how the terrain doesnt look smooth.

2 Likes

I don’t need to be spoon fed scripts so please say ideas and just explain them.

1 Like

Most people use math.noise(), or otherwise known as Perlin noise to generate terrain. as Perlin noise is smoothened and not completely random. It takes 3 parameters

  • X Coordinate
  • Y Coordinate
  • Seed

It returns the brightness value (0-1), of a pixel describes by the (x,y) coordinates, on the gradient of the given seed.

Perlin noise looks something like this:
image
and when used to make maps, is usually seen as a height map of the terrain. (Its very simple, but its somewhere to start)

Hope this helps! :grin:

1 Like

How could i check each individual pixel for its height?

1 Like

It already returns the value of each pixel, not the gradient. (described by the X,Y coordinate)

1 Like

But it is a single number. I don’t understand here how in one number it gives each pixel.

1 Like

You don’t use white noise (random) for terrain generation. You use normal noise (Perlin noise, Simplex noise, Value noise, etc).

Your terrain generator is fundamentally wrong.

You need an x and y position for each heightmap point, and based on the value generated you generate the terrain. There are way more issues, like not using a grid, not using chunks, etc.

1 Like