Procedural Cave Generation

Learn how to create procedurally generated caverns/dungeons for your games using cellular automata and marching squares. Full source code available on GitHub. Full playlist here.
Hope you enjoy :slight_smile:

Episode one (cellular automata):

Episode two (marching squares):

Episode three (creating the mesh):

Episode four (walls):

Episode five (region detection)

Episode six (connecting rooms)
Episode seven (ensuring connectivity)
Episode eight (passageways)
Episode nine (collisions and textures)

20 Likes

Very well done! Excellent format, execution and clarity. Looking forward to seeing further episodes!

1 Like

love it, and you sound like Stewie from family guy!

I’ve uploaded episode 2, covering the marching squares algorithm (to create a mesh out of the generated cave shapes).

1 Like

Thank you Sebastian for this great set of videos.

This is really impressive. I’m actually trying to do something much simpler (I think) and am having all sorts of troubles. Nothing like a random generator, just a custom Unity editor that would allow a game designer to click points in 3D space (currently against a plane) and connect the points together with meshes (edges), and then creating the polygon that the edges make when the designer clicks a point that they already made (points = sphere with a collider on it used during the creation process).

These tutorials give me some hope that it is possible for me to figure it out. :slight_smile: Thanks!

Thanks a lot for this, this comes in a handy as I’ve been looking into learn about procedural creation for a while :slight_smile:

edit: seems like the last tutorial(3) source code isn’t working correctly, no mesh is visible despite the small hickup everytime I hit the left mouse button or at the start due the cave generation code doing its magic, so I assume something is wrong with the meshgenerator code.

I added the mesh filter, tweaked values (width and height from 5 to 1000, random fill percent from 5 to 60) but still no mesh. :frowning:
The mesh filter component in the editor does show it isn’t empty, but the mesh name that is added is just blank space (though I think this is on purpose) and selecting doesn’t seem to be doing anything.
If you need more info let me know :slight_smile:

Hey, I’m not sure what could be going wrong. If you send me your Unity project though I’m sure I will be able to figure it out! :wink:

Hi everyone, I’ve uploaded episode four. Source code is now available here.

Been working on an algorithm for intelligently joining up the caverns with passages. Will start on the tutorial soon.


1 Like

Awesome!

Thanks Adam :slight_smile:

I’ve uploaded episode 05 - it covers the detection of the different regions of the map so that we can easily remove those we don’t want (e.g tiny rooms / walls).

Episode 06 now out, covering the connection of isolated rooms.

Uploaded episode 07, which shows how we can ensure that all rooms in the map are accessible.

Oh man. I don’t watch Breaking Bad or Game of Thrones, but I’m now getting to feel like the friends I know who do! Now I’m behind on my viewing and have to catch up!

2 Likes

This is an extremely useful algorithm video series. Thank you.

As a long term goal I’m hoping to mix elements of accidental noise, fractals, and such with cellular automata. I’m thinking different algorithms will produce different biome kind of effects.

But this video series has given me a jump start in comprehending things, where as these other approaches are quite difficult:

1 Like

Glad to hear it kuchaku, good luck with your project! I’m currently planning a series on generating land masses with perlin noise as a follow-up to this series, but your idea of combining different procedural approaches sounds intriguing. I’ll do some experimenting of my own :slight_smile:

1 Like

Is this series done? (I’ve not reached the end of the videos yet…)

I’ve still got one more episode to make before this series could be considered complete. I do have a few ideas for things I’d like to add to it after that (e.g. choosing good spawn points for doors/treasure chests/enemies and the like), but I might take a break from this series after the next episode to work on some other stuff, not sure yet!

1 Like

Great séries super usefull ! Just a question thought, have you tried generating big map ? The detecting region code(episode 5) is super slow. When i disable it, it creates the map 100 times faster. How would you go to speed thing up ?