Maze Generation: New and Improved!

After thinking through some options for using prefabs to generate mazes, I came up with a quick solution.  Rather than generating a random path between two known points, I just extend all open paths in a breadth-first search pattern.  The prefab elements are selected at random.  When all the routes are closed, the last piece becomes the goal.  I had to do some manipulation of the probabilities to make sure that really tiny mazes weren’t created.  So, I put in a test to see if a dead end was selected before 30% of the maze was done.  If so, it chose something else.  I also have the ability to weight the pieces with different probabilities, which I’m sure will come in handy.

Since the code is still in dev mode and there are no UI elements to speak of, it’s difficult to tell when the maze is complete.  The only indicator is that the input doesn’t work until the maze is complete.  I used coroutines in the generation function to enable me to see the maze being built.  That introduces some minor delays.  So, when playing this little demo, just be patient.  Each maze takes about 20-60 seconds to create.  I also turned the goal into a glowing green ball to help you figure out when you’re close.

Here’s the playable link: Maze Raider v0.2

Latest version: Maze Raider v0.6


  • Added music and some sound effects
  • Added compass
  • Added 1st person perspective (‘space’ to toggle)
  • Fixed bugs


  • Added pause menu to control mouse sensitivity and volume (Quit button doesn’t seem to do anything in WebGL build :-\)
  • Added some sanity checking to fix any weird things that happen with positioning or rotation
  • Added a start screen (I need some design skills…badly!)




  1. This would also be a lot more addictive as a mobile app. While I do appreciate the WASD dexterity exercise, you could really wiz through it just by pointing and dragging. My laptop touch screen gave me a glimpse of it. Looking forward to seeing this develop! (I like dungeons… err… mazes)

    1. Ultimately, I’d like to put this on the mobile app stores. I first want to get it to the point where people can justify paying $1 for it (which is a bit crazy considering how many hours I’ve put into this already :-\).

Leave a Reply