Seed based terrain generation

Hello! I was looking for some help building a seed-based terrain generation system, like Minecraft. If a world for one player has seed 2, and another player loads a world with the same seed, the same terrain would generate.

I have got some chunks that I could implement. Right now, each chunk (32x32 studs) just needs to be a different brick colour, and different structures should appear (think villages in Minecraft, and other structures, like jungle temples are rarer)

Please let me know if you have any ideas. Thanks!

I’ll leave you with math.noise, but just know that this is a very complicated subject in more than one aspect, if you’re going for the full concept of Minecraft generation.

I’ve seen that before, but didn’t understand how it could be utilised.

So the way that seeding works is that it makes your pseudorandom generation the same across each input, for example

local seed = 1 -- the seed value can be made consistent
Random:NextInt(1, 10) -- this should return a consistent value
--However, Math.noise generates its noise from its inputs, not from the math.randomseed() function
math.noise(x, y, z) will always equal math.noise(x, y, z)

Therefor you can use that seed value to adjust the inputs of Math.noise

local seed = 1
local chunksize = 16
local scale = 10.71 -- math.noise only works with floating point numbers, integers will return 0
for x = 0, chunksize do
     for y = 0, chunksize do
          local height = math.noise((x / scale) * seed, (y/scale) * seed) 



Thanks! Just to ask, how do I make it generate structures with rarity? For it to be consistent across worlds using the same seed, how would it be done?

You’ll need multiple noise maps for multiple different things. I’d give more in-depth information as I’ve worked directly with this sort of thing, but that’s also a project I’m still working on (albeit on the back-burner at the moment).

1 Like

Eek. Still don’t really understand it all. Do you have any code examples of using multiple noise maps?

There’s a lot of videos on YouTube about using perlin noise in regards to terrain:

There’s many more that have nothing to do with Roblox, but can still be relevant.


Thank you! I’ll take note of this.

Creating structures using noise can be done by using a second noise map with a higher-scale.

So instead of generating noise to get the height of a voxel in a chunk, set your noise inputs based on the chunk position itself. This will allow you to handle things such as biomes and structure generation by using a separate layer of noise.

The code for generating a noise sample is the same, you just have to change the input.

1 Like

Just a heads up: this only works if the RNG is called for each thing in the same order every time! If your goal is to have terrain that generates in chunks around the player as they move through the world, for “infinite” terrain, then you need to keep careful track of several RNGs to actually get the same result every time.

Just generating the terrain in a fixed number of chunks (and in a fixed order) is a lot of work already so this isn’t the first thing to deal with IMO, but it’s good to know for the future.

1 Like

Ah, thank you - this is starting to make more sense.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.