#2D Terrain Generation
1 messages · Page 1 of 1 (latest)
I've been working on a similar project, if you want procedural world generation, you might want to consider looking into Cellular Automata, i.e., setup a noise mesh from a (set or random) seed, then apply a smoothing process to it until you get some nice cave structures.
This is an example of what my current project can generate (still with testing sprites), using a smoothing function that literally just flips the tiles based on whether they have more than 4 or less than 4 neighours (in the 8 tiles around them).
In terms of performance, I'm not an expert by any means, but I've been creating a game object for each tile, and I can create, for example, a 1000 by 1000 map in about 5-10 seconds and with great performance, since it's just sprites and box colliders. I think you could theoretically further improve it by removing colliders from tiles that are surrounded by other solid tiles as well.
Hope this helps
@outer scarab For real performance you want to use at least some sort of chunking. (Note that I haven't used unity's tilemap system, I just kinda assumed it won't be flexible enough for me)
For my game, I divide the world into chunks of 16x16 tiles. So each chunk has a 1D array of Tile structs.
Rendering:
Each chunk gets a single SpriteRenderer that draws the whole chunk as one quad. Each chunk's texture is generated in a compute shader every time that chunk is modified. It reads the Tiles and their neighbors and "pastes" tile textures onto it from a tile atlas, according to some rules I set up.
Colliders:
Currently just a "greedy meshing" type script that generates and pools a bunch of BoxCollider2D to cover the tiles. I'll expand on this later to support triangles and maybe other shapes with PolygonCollider2D, but boxes will do for now.
This way both the texture and collider generation is super fast which is pretty important since the map is being modified all the time (breaking or building tiles/blocks).
I don't know your experience level though so I can't say if this is the best way for you to go about it - it takes some work to do properly. But you can always start simple.
In any case, I'd make sure to have your tilemap's underlying data as a chunked arrays of tile structs, so you can always swap the rendering/collider techniques later.
Just realized I didn't really answer anything about terrain gen but wesomeFaceFrom pointed out the main techniques: Noise + cellular automata.
I just wanted to give pointers on architecturing the map system for decent runtime performance.
You can also use Burst/Jobs for even faster noise generation and other operations later if you use structs for the tiles
@lethal tartan @dreamy carbon THX A LOT :0 this was really helpful
I’m prolly gonna implement the first one and research the second since my programming skills aren’t that advanced yet and the first seems slightly more straight forward ToT
My one question would be tho for the first method, I want to guarantee one path from point A to point B.
:/