Well, I'm trying to create a simple endless runner and -this may sound repetitive- I'm searching for ways to generate the terrain. The game will only have 3 types of ground tiles, ascending, descending and plain, and it should look (somewhat) like this:


So, what I want to say is that the terrain can only vary 1 unit of height.

I first thought of perlin noise, but I haven't found any information about restricting height variations. I've also thought about choosing randomly between the three posible tiles, but I still want that "natural randomness" that perlin noise can produce (very high hills, deep valleys, etc)

Any idea on how to procede?

Thanks! And please excuse my english.


2 Answers 2


You can still use Perlin noise. You simply need to constrain the random value to three values. Depending on how you're generating the noise, you'll get a value between -1 and 1, or 0 and 1. Whatever you have, just divide it by three, and place your tiles based on that.

float range = Perlin.max - Perlin.min
float value = Perlin.GetValue(xCoord)

if(value < range * (1/3))
else if (value < range * (2/3))

Essentially you're just taking the range of random values you can get from Perlin noise, and splitting them into three categories:

  • Less than 1/3
  • Between 1/3 and 2/3
  • Greater than 2/3

This gives you the benefit of gradient noise, while also constraining the output to three tile types.

  • \$\begingroup\$ Awesome, thanks! I was thinking about making the perlin noise affect the probability of placing each tile (if it's too high, then ascending tiles will apear more often). Would I get more or less the same result? \$\endgroup\$
    – vdrg
    Commented Sep 8, 2014 at 0:26
  • \$\begingroup\$ It's another way of doing it. It's going to be a subjective decision about which one you like more, or gives better results. Try both and see what you like. \$\endgroup\$
    – House
    Commented Sep 8, 2014 at 1:37

You can also set a target height to move towards, with smaller target height variations in between. Then you can have a sort of rolling hills effect where stuff still gets generally higher or lower as desired.

This is a great use case for recursion where you can tweak the parameters of each step to get different spacings.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .