A procedural cave generator made in Unity using cellular automata.
Tweak the slider bars and generate a new cave!
I was reading about cellular automata and wanted to apply it to a simple cave generation algorithm. For the most part, the level generation is complete. The end goal is to create a level maker, then the player can hop into the level, fight monsters, find treasure, etc, basically create and play.
I'm very interested in both traditional storytelling and how stories are told through interaction. I believe procedurally generated content (combined with other mechanics) can be an excellent tool in creating player-led narratives. Does this tool tell an interesting narrative that results in a compelling experience? No, but I hope to add onto it and explore ways that would combine narrative and procedural systems.
Currently, I have the navmesh being built at runtime, so creating a simple character controller and enemies should be no problem. Stay tuned for an update in the next couple of weeks.
The blue and green tiles are player spawn and exit. If they are off screen click the generate map button again until they are both on the map (bug fix coming soon!).
Other problems I'm looking to tackle:
1. Connecting the separate rooms by creating tunnels or stairs from other floors.
2. Player spawn, treasure, and enemies. Verify they are reachable via navmesh pathing.
3. Of course, the ability to play the level.
4. Simple art. Everything is already in 3D, just a simple unlit shader applied to the meshes to give it an old school look.
If you're interested in looking at the source code, download the unity package.
It's 3D! I promise!
Walls are spawned via the cellular automata algorithm, combined with my own tests. At runtime, a navmesh is baked to determine what areas are traversal or not. My long term goal is to create simple low poly assets to give the level a more "cave-ey" feel, rocks, slopes, formations, etc.
A major issue I wanted to solve was the rooms. Running a simple cell automata algorithm would create many separated rooms (as show in the first image below). The level becomes less playable automatically because of the walls that separate these rooms. To solve this problem, I wrote a function that would look for areas to "punch in" and create tunnels between open spaces that were near to each other.
After running this custom algorithm, this would create the level you see in the second image above. The result has more playable space and less separated rooms. Since writing this algorithm, I've added pathing via Unity's navmesh components. This will help when spawning various objects to see if they are pathable or not. Stay tuned for more updates as I work on adding more surprise and story to the spawned objects. Thanks for checking it out!
©2021 Bruce Evans