Random World Generation

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
Post Reply
User avatar
Script47
Posts: 147
Joined: Thu Nov 21, 2013 6:11 pm

Random World Generation

Post by Script47 »

I was wondering if anyone who who has the theoretical understanding of a random world generator, to teach me the workings of a random world generator i.e how does it work? What sort of algorithms am I looking to be using? What is the best way (in your opinion) to go about doing such a task? So basically, the ins and outs of one. I don't mind if you go in to detail (write an essay if you must ;)) as I want to get a clear understanding of how it all works and the basic structure of the code behind the world generator.
User avatar
Xaos
Posts: 946
Joined: Wed Jan 11, 2012 4:01 am

Re: Random World Generation

Post by Xaos »

What kind of world? I forget who but someone explained how they made a random world for a nifty sidescroller plane game. For an rpg, you need to make certain objects so far apart to allow player movement (like trees cant be within 10 in-game feet of each other), otherwise theoretically you could just randomly place things along each axes, x, y and z if you have 3D.
User avatar
kaos78414
Posts: 507
Joined: Thu Jul 22, 2010 5:36 am

Re: Random World Generation

Post by kaos78414 »

I've built a terrain generator engine and messed around with a tree generator as well. Personally, for terrain (2D tile maps, in my case), I used the diamond square algorithm to generate a "height map" - this is a 2d array (an array of arrays, accessed something like array[x][y]) of values that represent the "height" of that tile.

There are some other algorithms that can get you something similar, such as the perlin noise algorithm. Anyway, once you get past generating a height map, it's all up to you. For example, you might loop through the array and anything that is below a certain value you consider water. Then you can create another noise map of the same size (this one could be set to be a bit more random), and place trees and other flora through that, based on an arbitrary minimum value.

For something like rivers, you path from a starting point (say a large body of water), using A*, then sort of "settle" the water points into the lower areas of the height map, and extend out from those.

I suppose this is more of a "zone" generator, not so much a world one. But a world could just be an expanded version of what I've just gone over. So you'd create a world height map, place biomes based on their locations in reference to their surrounding tiles, and then for each index in the array, loop through just like the above and place flora and other details more finely.

Anyway, this is just one way you could go about generating a world. Here is an interesting article that uses some different techniques and also includes source code: http://www-cs-students.stanford.edu/~am ... eneration/
w00t
User avatar
a_bertrand
Posts: 1537
Joined: Mon Feb 25, 2013 1:46 pm

Re: Random World Generation

Post by a_bertrand »

For my cubicverse I used a perlin noise generator (check out on the net what it is). This generates my base terrain. On top of if, I added different kind of terrains depending on the height and depending on the X,Y coordinates (desert, grass, snow lands for example). Most world generators are based on some noise generators being a perlin noise or more complex one. Try by yourself some flat gray scale one, then replace the darker gray with "blue" for water, and the remaining green for grass, then depending on the value of the base "gray" you can have sand (which will be near the water) then grass, then tree for the top of the "hills".
Creator of Dot World Maker
Mad programmer and annoying composer
User avatar
Script47
Posts: 147
Joined: Thu Nov 21, 2013 6:11 pm

Re: Random World Generation

Post by Script47 »

kaos78414 wrote:I've built a terrain generator engine and messed around with a tree generator as well. Personally, for terrain (2D tile maps, in my case), I used the diamond square algorithm to generate a "height map" - this is a 2d array (an array of arrays, accessed something like array[x][y]) of values that represent the "height" of that tile.

There are some other algorithms that can get you something similar, such as the perlin noise algorithm. Anyway, once you get past generating a height map, it's all up to you. For example, you might loop through the array and anything that is below a certain value you consider water. Then you can create another noise map of the same size (this one could be set to be a bit more random), and place trees and other flora through that, based on an arbitrary minimum value.

For something like rivers, you path from a starting point (say a large body of water), using A*, then sort of "settle" the water points into the lower areas of the height map, and extend out from those.

I suppose this is more of a "zone" generator, not so much a world one. But a world could just be an expanded version of what I've just gone over. So you'd create a world height map, place biomes based on their locations in reference to their surrounding tiles, and then for each index in the array, loop through just like the above and place flora and other details more finely.

Anyway, this is just one way you could go about generating a world. Here is an interesting article that uses some different techniques and also includes source code: http://www-cs-students.stanford.edu/~am ... eneration/
Yes, I read up a little about Perlin Noise Algorithm last night. Thanks for the in-depth reply. Really helpful. I also came across that link last night too. :)
a_bertrand wrote:For my cubicverse I used a perlin noise generator (check out on the net what it is). This generates my base terrain. On top of if, I added different kind of terrains depending on the height and depending on the X,Y coordinates (desert, grass, snow lands for example). Most world generators are based on some noise generators being a perlin noise or more complex one. Try by yourself some flat gray scale one, then replace the darker gray with "blue" for water, and the remaining green for grass, then depending on the value of the base "gray" you can have sand (which will be near the water) then grass, then tree for the top of the "hills".
I will most likely check out Perlin Noise as it has been recommended quite a bit.
User avatar
Script47
Posts: 147
Joined: Thu Nov 21, 2013 6:11 pm

Re: Random World Generation

Post by Script47 »

So after some digging around I found these two, one (http://mrl.nyu.edu/~perlin/noise/) which isn't written is C# but I could suspect that it wouldn't take much to convert and another article (http://devmag.org.za/2009/04/25/perlin-noise/) which is quite an easy read *hopefully* (or it seems so far).
User avatar
Script47
Posts: 147
Joined: Thu Nov 21, 2013 6:11 pm

Re: Random World Generation

Post by Script47 »

I thought I would start a lot smaller before jumping right in. This is what I made.
Post Reply

Return to “Advanced Help and Support”