Hello guys,
I’m currently working on a Game similar to the Flashgame “DigToChina”.
My plan is to generate the map with my Dirt, Stone and Ore prefabs.
All prefabs are squares that are 1 Unit in size, and arranged in a grid, which should make it easier, hopefully.
I also want it to not be completely random, where the different prefabs are spawned, since dirt should be on top and stone deeper down. Also ores should get more common in deeper layers and some only generate deep down.
Sadly, I have absolutely no idea how I should go about this. I’m fairly new to developing games in Unity.
I’d also love, if the world was infinite, or atleast very very big. But I’m not sure, if thats a good idea.
Some help would be really appreciated
There are of course several ways you could do this. But for a simple start I would use UnityEngine.Mathf.PerlinNoise Unity - Scripting API: Mathf.PerlinNoise
Use one map for every material you want and the one that provides the highest value sets the material. You could also filter this value with a function which increases or decreases the value depending on e.g. depth. You could threshold it to generate clusters. There are so many things you can do with mathematical operators.
If you also need to place prefabs inside clusters then you could look up poisson disc sampling in order to generate prefabs that have a minimum distance between each other.
I would not recommend using a prefab for each tile, if you are using 2d then do a tilemap. If 3d, generate a mesh. Otherwise you will hit performance issues soon.
Perlin noise can extend into (near) infinity so you just need to unload chunks that are far from the player.