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!)