February 25, 2014

You can now play with this!

Inspired by supermeerkat’s post about his cave generator (found here), I wanted to see what all I could pull off. I started out by researching various procedural generation algorithms, and eventually settled on one aptly called “Drunken Walking”.

The concept itself is quite simple. Given a starting set of coordinates, you move that point in a random cardinal direction each cycle (or walk, as I’ve come to reference it as). This has the effect of giving you a random path, but one that’s always connected. The downside however is you generally don’t get anything more advanced than random blobs. That’s when you bring in the concept of biases.

The bias concept is also quite simple. Given a random chance, the direction the point is moved is based on certain criteria instead of a random direction. The code I’ve written includes three of these. A corridor bias, which increases the chance of the point to move in the same direction, one that influences the point to move towards the center of the grid, and once that influences it back towards the origin coordinates.

I also went ahead and added two more things that may not generally be associated with this particular algorithm. One is cave smoothing, which simply scans through the entire grid and turns any small gaps into part of the surrounding cave, and the ability to prevent going back to already visited cells.

If you’re interested in any of this, I’ve linked both the generation script, and a script for rendering it inside Unity, below.

DrunkenGenerator.cs

Handles the actual map generation, and is completely separate from Unity

CaveRenderer.cs

Handles rendering the map generated via the script above

GuiController.cs

A simple GUI controller for generating maps whilst in-game

I realize I’m not the best at writing posts about what I’ve accomplished. Tips on that would be nice ;)

50 Kudos