P O L Y G E N

Maze Algorithms

My first project is going to be a sci-fi level generator using Synty's SciFi Space Assets. You can find them here. This pack is full of 3D models that are sized perfectly for what I'm trying to do. They are designed to be building blocks that fit together seamlessly, which is perfect for writing code to assemble them.

The first thing I need to do, however, is to figure out what approach to take for building a level to begin with. I also found some awesome courses on Udemy by Dr. Penny de Byl. In one of her courses, she talks about several maze generation algorithms. So I decided to try some of them out.

Penny describes how by first setting up a grid of cubes, you can then start to carve out a maze by subtracting cubes. Once your maze is how you want it, you can then start analyzing the maze and replacing cubes with actual 3D models of wall, floor and ceiling pieces.

This one is called "Prim's Algorithm", which involves starting with a single node and moving to adjacent nodes and moving outward.

This is definitely a complete maze, but there are a lot of dead ends. In playing around with some other algorithms, I was able to get some mazes that I thought were more fluid and possibly more fun to traverse.

This one is called Wilson's Algorithm.

And this one is called "Recursive Depth First Search" algorithm and is possibly my favorite so far.

As cool as these are, they aren't what I'm looking for. I needed something that wasn't so much of a "maze", I guess, and more of something with longer hallways and rooms. I imagine the interior of a big space cruiser being easier to get through. Like, if Captain Picard were to be called to the bridge in an emergency, would he really have to walk a maze like this in order to get there? The Enterprise would have to have been designed by a bunch of alcoholic clowns or something.

So, I set out to write my own algorithms and came up with some that are a lot more uniform. This layout will work better for creating and finding rooms within the ship and is laid out a lot more like the demo scene that comes with the SciFi Space pack.

The approach I took for this was to first carve out a hall around the perimeter of the rectangle, and then subdivide that shape over and over at random positions in order to get more of an imperfect grid layout.

I can now start to see how this will come together. With a little more tweaking, I think I can get this to be a little more complicated with less halls that are so long. This should make the levels interesting enough to walk through and explore without making them take hours to get from one side to the other.

Previous Post

The Beginning

Next Post

Bringing My World to Life