Random Terrain Generation

Hi, How do i generate random terrain every time I start up the level. I don’t want it to be voxely or cubic like mine craft i want it to look like the i used the built in terrain generation tool for unity. To sum up the question I know how to create terrain but I just want to know how to make it so its random every time. Thank you in advance for your answers. The code on how to do it would be amazing.

Thanks, Brandon

You can create a terrain using Mathf.PerlinNoise():


You can randomize the look by changing two things. First, you can randomize the tileSize. Something like:

  tileSize = Random.Range(7.5f, 18.5f);

And then you can randomize an offset into the perlin noise surface:

  float xOffset = Random.Range(0.0f, 7.5f);
  float yOffset = Random.Range(0.0f, 7.5f);

And change the height calculation:

  heights[i, k] = Mathf.PerlinNoise(((float)i / (float)terrain.terrainData.heightmapWidth) * tileSize + xOffset, ((float)k / (float)terrain.terrainData.heightmapHeight) * tileSize + yOffset)/10.0f;

You can also randomize the divide by 10 at the end of the previous line. Smaller numbers mean higher average peaks.