Procedural Generation

Random Cave Generation

This week in my Unity quest, I took a step back from the stars and went “underground” in search of a better way. I want to make a seemingly unlimited expanse of space. In both Starlight Arcade and future games. Stars of every color, planets, comets, nebulae, everything. To do that, I believe procedural generation is the best bet. If you aren’t familiar with what this is, my very inexperienced experience with the term has shown me that procedural generation can use algorithms to create textures, content, celestial bodies, etc. in-game primarily through the use of code rather than traditional human interaction. Ultimately, to me, this says that procedural generation has the capability to both leverage my coding efforts and transcend my personal level of creativity.

For example, take a look at the tutorial by Takumi on “Procedurally Generated Nebulae in Unity3D”. This tutorial seems very complicated, but take a look at what he is able to accomplish. With some masking, coloring and code, he is able to make some gorgeous nebulae and, thus, some gorgeous space scenery.

That tutorial is the current end-goal in my procedural generation endeavors. However, it’s a little closer to the deep end than I’d like when I haven’t learned how to swim yet, so to speak. I’m also a little tired of staring at stars for the moment, so I went for something more my speed in Sebastian Lague’s 9-part “Procedural Cave Generation Tutorial”.

Needless to say, when Unity marks a tutorial as “advanced”, they aren’t lying. So far, only three of the nine parts in, I’m treading water; but I am gathering a lot of knowledge. The author’s bio says he has been making games since he was 12 and working with the Unity engine since 14. He knows his stuff. And he explains everything he is showing in the tutorial very well. While I learned a lot here, I also learned that there’s a lot more to learn. Procedural generation will likely take a large number of passes until I am able to create something completely original, but the thought of being able to do that is very exciting.

If you would like to take a look at how things are going, hit the button below. Simply click inside the game window that opens to see the game generate new, random meshes for a different cave scene every time.

Play

Things I learned from this tutorial:

  • Cellular Automata – using mathematical models and simple units to create more complex structures (caves in this example).
  • Marching Squares – using a system smaller sections in squares, within a grid of squares, to create absent and present triangles via algorithm. This can be used to smooth grids and create meshes.
  • Classes in C# – gives you the ability to group variables, methods, etc. into a reusable unit. Kind of like a CSS class on steroids.
  • That I have A LOT more to learn.