Procedural Terrain Generation with Perlin Noise in Unity

Unity Game Architecture Guide
Unity Game Architecture Guide (Best Patterns for Clean Code)
June 21, 2026
Biome-Based Procedural Terrain in Unity (Snow, Desert, Forest)
June 29, 2026
Unity Game Architecture Guide
Unity Game Architecture Guide (Best Patterns for Clean Code)
June 21, 2026
Biome-Based Procedural Terrain in Unity (Snow, Desert, Forest)
June 29, 2026

Procedural Terrain Generation with Perlin Noise in Unity

Procedural terrain generation allows developers to create vast and unique environments automatically. Instead of manually designing every mountain, hill, or valley, algorithms generate terrain dynamically.

One of the most popular techniques for procedural terrain in Unity is Perlin Noise.

Perlin Noise produces smooth, natural-looking randomness, making it perfect for generating landscapes.


What Is Perlin Noise?

Perlin Noise is a gradient noise algorithm commonly used in procedural generation. Unlike pure random values, Perlin Noise produces smooth transitions between values, which results in natural terrain shapes.

Unity provides a built-in function for this:

Mathf.PerlinNoise(x, y);

The function returns a value between 0 and 1.


Basic Terrain Generation Concept

To generate terrain using Perlin Noise:

  • Create a grid of vertices
  • Use Perlin Noise to determine the height of each vertex
  • Construct triangles to form the mesh

The noise value controls the elevation of the terrain.


Simple Procedural Terrain Script

using UnityEngine;

[RequireComponent(typeof(MeshFilter))]
public class ProceduralTerrain : MonoBehaviour
{
    public int width = 100;
    public int height = 100;
    public float scale = 20f;
    public float heightMultiplier = 5f;

    void Start()
    {
        Mesh mesh = GenerateTerrain();
        GetComponent<MeshFilter>().mesh = mesh;
    }

    Mesh GenerateTerrain()
    {
        Mesh mesh = new Mesh();

        Vector3[] vertices = new Vector3[(width + 1) * (height + 1)];
        int[] triangles = new int[width * height * 6];

        int v = 0;
        for (int z = 0; z <= height; z++)
        {
            for (int x = 0; x <= width; x++)
            {
                float noise = Mathf.PerlinNoise(x / scale, z / scale);
                float y = noise * heightMultiplier;

                vertices[v++] = new Vector3(x, y, z);
            }
        }

        int t = 0;
        int vert = 0;

        for (int z = 0; z < height; z++)
        {
            for (int x = 0; x < width; x++)
            {
                triangles[t++] = vert;
                triangles[t++] = vert + width + 1;
                triangles[t++] = vert + 1;

                triangles[t++] = vert + 1;
                triangles[t++] = vert + width + 1;
                triangles[t++] = vert + width + 2;

                vert++;
            }
            vert++;
        }

        mesh.vertices = vertices;
        mesh.triangles = triangles;
        mesh.RecalculateNormals();

        return mesh;
    }
}

Understanding the Key Parameters

Scale

Controls how stretched the terrain is. Larger values produce smoother terrain.

Height Multiplier

Controls how tall the mountains and valleys become.

Width and Height

Determine the terrain size.


Adding Terrain Variety

To make terrain more interesting, developers often combine multiple layers of noise (called Octaves).

float noise = 0;
float amplitude = 1;
float frequency = 1;

for(int i = 0; i < 4; i++)
{
    noise += Mathf.PerlinNoise(x * frequency / scale, z * frequency / scale) * amplitude;
    amplitude *= 0.5f;
    frequency *= 2;
}

This creates more detailed terrain features.


Improving Performance

Procedural terrain can become expensive if not optimized. Consider these tips:

  • Generate terrain in chunks
  • Use Level of Detail (LOD)
  • Cache generated meshes
  • Use Unity Jobs and Burst for large worlds

Common Uses of Procedural Terrain

  • Open world games
  • Infinite terrain systems
  • Roguelike maps
  • Voxel terrain engines

Final Thoughts

Perlin Noise is one of the most powerful tools for procedural generation. With just a few lines of code, you can generate complex landscapes that would take hours to design manually.

Once you understand the basics, you can extend the system with biomes, rivers, caves, and dynamic world generation.


 

Leave a Reply

Your email address will not be published. Required fields are marked *


Skip to toolbar