top of page

Terrain Generator

The terrain generator is a simple and quick tool to create terrain, just add the script to an object, and watch as the magic happens! There are many settings you can change to perfect your level.

Snap2.PNG
Snap4.PNG
terrain.PNG
Snap5.PNG

How it Works

The terrain generator uses perlin noise to generate its' terrain. Perlin noise is basically a texture with a bunch of values which slowly transition from 1 to 0, but that is a very simplified and likely incorrect descpription. The generator gets values on the page and sets the mesh to have a y height of that value multiplied by values you set.

Snap3.PNG

Perlin noise was created by Ken Perlin. He created a technique which creates a smoother texture then the box standard random noise (The left is random noise, the right is perlin noise).

220px-White-noise-mv255-240x180.png
perlin-noise-texture.png

To create perlin noise, first a grid of points are made. Each point then is given a random vector, to visualise this, imagine a grid of points with arrows pointing in random directions.

Once it has created these points, all that it needs to do is make spots with arrows pointing towards them darker, and areas without arrows lighter! Almost like magic, the perlin noise function is born!

256px-PerlinNoiseGradientGrid.png

Now that we have a perlin noise function, all we need to do is call the function PerlinNoise(), pass in a vector2 for where on the grid we want to sample, and we get out a value between 0 and 1! 0 being black and 1 being white!

​

What our terrain generator does is create a mesh with a large grid of points. We then go through each point and ask perlin noise what value it should have, anywhere between 0 to 1. We then affect that value by all the maths we have (which we will talk about later), and set the y position (height) of this point to be that value.

Customisation

I have set many variables within the function to change how the terrain generates, and all of them are quite interesting!

Cube Distance / Cube Scale

If you have looked at some of the example images, you will notice the terrain is made up of flat tiles next to each other at different heights. Cube Distance and Cube Scale controls these. Cube distance is simply how far away each tile is from each other, increasing this above 0 creates slopes between the tiles. Cube Scale controls how large each tile is.

Scale

When sampling values from the perlin noise, the scale effects how far each sampled point is. When the scale is smaller, the terrains height will lerp smoother, and the reverse will happen when its larger.

Power

When recieving a value between 0 and 1 from the perlin noise, the value is raised to this power. This will creates mountains within the terrain.

Height Multiplier

When recieving a value between 0 and 1 from the perlin noise, the value is multiplied by this value.

Gradient

The gradient determines the color of the terrain. When each point is created on the generation, it sets the color of that point based on this gradient. Values on the left are the color at low points, and the right colors at high points.

Snap1.PNG
bottom of page