Having problems with random terrain generation

  1. What do you want to achieve? Keep it simple and clear!
    i want to achieve a smooth terrain generation like minecraft plains biome

  2. What is the issue? Include screenshots / videos if possible!
    it keeps glitching and not generating the noise in x axis properly

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    i tried searching videos on youtube, tried looking on developer hub, but it keeps glitching
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

here’s my code of the terrain generation:



worldsize = 100
blocksize = 3
layers = 5
chunksize = 10
waterlevel = -2
--World Generation
game.Workspace.GameLoaded.Value = false
seed = math.random()
print('Seed: ' .. seed)
 frequency = 12
 amplitude = 8
 totalx = 0
totalz = 0
topblock = game.ReplicatedStorage.Blocks.Grass
for chunkindexX = 1,(worldsize / chunksize) do

	
	game["Run Service"].Heartbeat:Wait()
	for chunkindexZ = 1,(worldsize / chunksize) do
		
		local chunk = Instance.new('Model',game.ReplicatedStorage.Storage)
		chunk.Name = 'Chunk: ' .. chunkindexX .. '/' .. chunkindexZ
		local chunkpos = Instance.new('Vector3Value',chunk)
		chunkpos.Name = 'ChunkPosition'
		chunkpos.Value = Vector3.new(chunkindexX* (chunksize * 3) + 3,0,chunkindexZ* (chunksize * 3) + 3)
		for x = 1,chunksize do
			totalx = totalx + 1
			for z = 1,chunksize do
				
				totalz = totalz + 1
				local block = topblock:Clone()
				block.Parent = chunk
				noise = math.floor((math.noise(seed,totalx/frequency,totalz/frequency) * amplitude)) * 3
				block.Position = Vector3.new( chunkindexX * 30 + x * blocksize,noise,chunkindexZ * 30 +  z * blocksize)
			
				block.Size = Vector3.new(blocksize,blocksize,blocksize)
			
				for i = 1,layers do
					if i < 4 then
						local block2 = game.ReplicatedStorage.Blocks.Dirt:Clone()
						block2.Parent = chunk
						block2.Position = Vector3.new(block.Position.X,block.Position.Y - (i * blocksize),block.Position.Z)
						block2.Size = Vector3.new(blocksize,blocksize,blocksize)
					else
						local block2 = game.ReplicatedStorage.Blocks.Stone:Clone()
						block2.Parent = chunk
						block2.Position = Vector3.new(block.Position.X,block.Position.Y - (i * blocksize),block.Position.Z)
						block2.Size = Vector3.new(blocksize,blocksize,blocksize)
					end
				end
			end
		end
	end
end

any help is appreciated!

1 Like

Terrain generation is definitely down the more complex path of coding. You’ll definitely need to use math.noise() for that. I would recommend either looking at other forum posts or watching tutorial videos on terrain generation on YouTube. There are quite a few good ones for various different methods and outcomes.

While they’re all good, just know that none of them seem to cover more complex stuff such as biomes with smooth transitions between each other. Also if you’re trying to replicate Minecraft or something similar in Roblox, I wouldn’t recommend it at a beginner or even intermediate level (at least if you’re aiming for a complete game with world saving) as it can get extremely complicated, especially when trying to work within the limitations of Roblox.

But regardless of what your goals are, good luck. :+1:

Edit: Nvm on the math.noise, I just saw that you were using it.

1 Like

thanks for your response, but i have alreadly looked a lot in youtube and developer forum, but it keeps generating only in the z axis like a 2d game

1 Like

Here are a few different videos that may help:

math.random for map generation is -15 social credit, use math.noise as @MightyDantheman suggested

1 Like

but im alreadly using math.noise!
here:

Why are you doing this? It adds up automatically itself. You are basically doing 2,4,6,8, delete that line

totalx is the position in the world, x is the position in the chunk

if i used x instead of totalx all of the chunks would be the same

You still don’t need to do it, I recommend you set the

As the world position, and chunk as end.