I'm working on a 2D top down game. The map is randomly generated using a perlin noise. This is what the code looks like: Code (CSharp): using UnityEngine; using System.Collections; public class MapGeneration : MonoBehaviour { public int MapHeight; public int MapWidth; private int seed; int[,] map; public float TileSize; public float noiseStrength = 10.0f; void Start() { Generate(); } void Generate() { seed = Random.Range(0, 100000); int treeSeed = Random.Range(0, 100000); map = new int[MapWidth, MapHeight]; for(int x = 0; x < MapWidth; ++x) { for(int y = 0; y < MapHeight; ++y) { float noise = PerlinNoise(x,y, seed, noiseStrength) + CircleGradient(x, y); float treeNoise = PerlinNoise(x,y, treeSeed, 10f); if (noise < 0.5f) map[x,y] = 3; // Mountain else if (noise < 0.8f) map[x,y] = 2; // Land else map[x,y] = 0; // Water if(map[x,y] == 2 && treeNoise < 0.4f) map[x,y] = 1; // Trees } } BuildMap(); } void BuildMap() { for(int x = 0; x < MapWidth; ++x) { for(int y = 0; y < MapHeight; ++y) { GameObject Tile = (GameObject)Instantiate(Resources.Load("Tiles/Tile" + map[x,y]), transform.position, Quaternion.identity); Tile.transform.position = new Vector2((x * TileSize - (MapWidth / 2) * TileSize) + TileSize / 2, -(y * TileSize - ((MapHeight / 2) * TileSize) - TileSize / 2)); Tile.transform.parent = transform; } } } float CircleGradient(float x, float y) { int centerX = MapWidth / 2; int centerY = MapHeight / 2; float distanceX = (centerX - x) * (centerX - x); float distanceY = (centerY - y) * (centerY - y); float distanceToCenter = Mathf.Sqrt(distanceX + distanceY); distanceToCenter = distanceToCenter / MapWidth; return distanceToCenter; } float PerlinNoise(float x, float y, float seedToUse, float strength) { float noise = Mathf.PerlinNoise(seedToUse + x / strength, seedToUse + y / strength); return noise; } } And this is the result: Blue is water, Light green is grass, Dark green are trees, and the grey is stone. The entire map is made of tiles so the next thing I would like to do is add auto-tiling. I've never done this before and have no idea how to get started. Someone told me it was a real annoying thing to do because you have to check every tile in every direction and tell what tile needs to have which visual. But I remember reading somewhere you can calculate a number which will be linked to the visual of that tile. So I was hoping someone could help me with this and if you see something in my code that I could do better I'd love to hear because I'm still learning.
Pearbook, I haven't had time to play with this myself, but I was recently looking into something similar and found this resource: http://www.oldschoolpixels.com/?p=252 . It claims to be a C# script that can be used to match a tiles sprite based on the tiles around it, which I think is what you are looking for. Like I said, I haven't been able to try it out yet, but it looked promising! Good luck.