2d Top-Down Perlin noise map using Mathf.PerlinNoise

Okay I don’t really like asking for help, but here I go:
I’ve been trying to make a 2d top-down terrain generator for my game ( something like dwarf fortress, just… simpler), and I managed to make one (Hooray!), but the terrain my script generates isn’t really what I was trying to do.

I hope you get my idea, I want a more realistic, bumpy terrain.
Here is my code:

public class Generator : MonoBehaviour {

	public GameObject dirtPrefab;
    private GameObject C;
    private float maxX = 320;
    private float maxY = 320;
    private int seed;
    void Start()

    private void Regenerate(){
        float width = dirtPrefab.transform.lossyScale.x / 5;
        float height = dirtPrefab.transform.lossyScale.y / 5;
        for (float  i = 0; i < maxX; i++)
            for (float k = 0; k < maxY; k++)
                var perlin = Mathf.PerlinNoise(i / 10, k / 10);
                if (perlin >.5f)
                    C = (GameObject)Instantiate(dirtPrefab, new Vector3(i * width, k * height, 2), Quaternion.identity);
                    SpriteRenderer Sr1 = C.GetComponent<SpriteRenderer>();
                    Sr1.color = Color.green;

Any ideas on how I can get a better terrain generator?


First, you’re using 0.5 as a cutoff for “land” vs “not land”. But what you really want to do is use that as a height value. You can see an immediate difference by changing your color:

Sr1.color = new Color(0, perlin, 0);

This will make your land color change.

Second, you can try messing with your divisor when generating the Perlin noise. Right now you’re using 10, but try using different numbers to see what the results are.

Third, you can try to offset the returned perlin value based on how far from the center of the map you are. Areas near the center would have a higher value, and areas farther away would have a lower value. This would kind of force the map to generate a mountain in the center with ocean around the edges.

I know this post is quite old, but does anyone know how I could make this into an infinite terrain? Thanks

Edit: Sorry. This should be in the comments section.

Mix the perlin noise with a radial gradient to get an island in the center. I found an excellent blog post with various examples: