Procedural Cave Generation
The Project
This level generation tool was created as the final project for UCSC’s Generative Design class, a course about applying procedural generation techniques to game development. We set out to make a 3D cave generator inspired by Minecraft and Deep Rock Galactic, two games with procedural cave systems. It was also visually inspired by this scene from Snow White with sparkling cave walls.
Technical Achievement
For this project, I decided to use the marching cubes mesh skinning algorithm to convert a set of 3D data into a level that is walkable by the player. The process of level generation happens like this:
A world space in initialized as empty according to the size set by the player
The world space is then modified by our Perlin worms
Starting from the center of each “chunk” of the world, the worm algorithm carves out caves of a random size and length
In every chunk where multiple worms intersect, this creates large open areas (hubs) where key game elements could be placed
Depth-first search in an arbitrary order is used to create paths between the hub of each chunk, guaranteeing that the entire level is reachable from any arbitrary point in the level
At this point, we just have 3D arrays of (-1 to 1) values. This data is passed to the mesh skinner, which generates meshes as well as colliders for the level
The level is then randomly seeded with crystals that provide light and help the player to differentiate between the often similar looking caves
Because all of the randomness in this generator either originates from Perlin noise or a seeded random number generator, the levels are completely seed-replicable (i.e. the same seed will get you the same level every time you play).
As an added feature for game developers, once a level is generated that the user likes, there is a single button press needed to export all of the meshes to files, removing the generation time needed to load a level.