Understanding the generation of a basic heightmap/colormap

Message to Moderator: This is a different question than the one I posted earlier, please don’t delete this!

Hey guys,

Basically, I want to know how to create a terrain through code. Just something simple, like the image bellow. It needs to be two flat levels, and have a strait (strait up and down, not strait across the level) cliff separating them. Also, if it’s possible, I would like it to also generate a riverbank and waterfall that stretches to the sea (almost exactly like the picture bellow).


I am sorry for all the topics I’ve posted about this recently, but I don’t understand it, and would really appreciate some help. Thanks again for all your help and comments!


P.s. The picture is from a game that I’m remaking, so please pardon the little houses and such.

The easy answer is try. There is no single solution to this problem (although I’ve previously shown you how to get it all into Unity itself at How to procedurally generate a super simple terrain - Questions & Answers - Unity Discussions ).

This is a fundamental feature of your game, so it’s worth figuring out this part yourself - it’s not really fair to ask someone else to give you a pre-packaged, complete terrain generator. It’s a lot of work and it needs to be customised for each game.

And it’s actually a lot of fun if you are a developer at heart.

If you then run into specific problems with your terrain generator, feel free to ask. People can easily deal with the smaller problems.

But these also aren’t unity-specific questions. Perhaps you’ll get better answers at general game-development forums.

But if you want a quick introduction…

Start with the height map, because the textures you use will most likely depend on the heights.

  • Start from the sea (low height values) and then smoothly increase the height in one direction (so you raise up out of the water and onto dry land).

  • Create random hills. You usually do that by adding random offset to the points you made in the previous step, then smoothing them out again when you are done. The most popular approaches use fractal noise (which tend to generate soft, realistic hills), but you don’t have to go that far if you don’t want to.

  • Randomly create your rivers by digging them into the terrain. Make sure you start from one end and work towards the ocean.

  • You will need to go through and use some technique to make sure every piece of your map is accessible. This is a little difficult, but could be done with some kind of ‘flood fill’ algorithm. If an area is inaccessable, add a bridge or ramp.

  • Then ‘colour’ your map by using different textures. If it is under-water, use sand. If it is above water, use grass. If it’s half way in between, blend the two. If it is paricularly steep, use rock.