Physics Based Dungeon Generator Post-Mortem
For the last several months, I have been working on a Dungeon/Maze Generator as a bit of an educational side project. Some of you have seen my progress posts over these months and have seen the troubles involved with the project. But over the last week, I have come to a point in which I feel that this code is as fast and reliable as I can get it using the current methods. With this in mind, I have decided to release the most recent project as a public GitHub for others to explore and perhaps improve on.
The concept was to create a generator that used prefab rooms and passageways for a more structured and 'planned' environment feel. This could allow a designer to develop and build a few handful of rooms that match a theme. And as long as they are designed to connect to other rooms, there wouldn't be a limit to the layout of the maze/dungeon. The rooms could be your typical fantasy dungeon or castle, a modern horror hospital or even a cave system.
At present, it can create a 500+ room dungeon in between 25 and 40 seconds depending on the platform running it. This is a good speed, in my mind, for a dungeon of this size to be created, but it doesn't yet match my desires for my intentions. In it's current form, it is ideal for procedural generation of a dungeon in advance of the player encountering it. For instance, the code could be used at design time to quickly build out a dungeon for a designer to come in and tweak and customize. Or it is fast enough with a light enough footprint, in my opinion, to generate a dungeon upon the player's arrival in the dungeon vicinity allowing for different experiences with each play through. For the later, I would recommend further coding to allow for randomization in each generated room.
And while I seem to be moving on from this project, It is simply that I have decided to take a different approach to the same concept. The current version uses Unity3D's physics system to detect the colliders of the rooms to prevent overlap. This system does work but has it's limitations as well, primarily speed. Because of the way that Physics are coded in Unity, a physics object can take up to two frames to appear to the rest of the active collection for interaction. And while two frames doesn't seem like a lot of time, it is enough that the code could have moved on to decided the placement of other pieces that would have interacted the ones that aren't reacting yet. I found that this leads to rooms that are overlapping and 'phased' through one another. After many attempts to account for this, I found that only adding an artificial delay into the code to work.
The other issue I found was that Unity's Physics system did not like to work well with detecting multiple colliders for a single object. This left me to make rooms that acted like rectangular tiles that could not overlap. So any oddly shaped rooms had to have a box collider that was equal to the most extreme dimensions of its shape. This prevents the code from making anything that move closely resembles a labyrinth or hedge maze, both of which I had hoped to be able to pull off.
So after a short break to pick up some related coding skills, namely inspector editing, I plan to return to this challenge and approach it from a matrix or grid paper method. My hope to is to bring the construction time down to near instant (or as close as I can get) and to allow for a tighter layouts with minimal gaps between rooms.
https://github.com/ThomFoxx/DungeonGeneratorDemo/tree/master
Awesome write up, Thomas!
So bad ass!!! My game could use this.
Hey, Jon mentioned something about full stack, c# to JSON... is that part of the VR course or something else completely? I've been wanting to get into the whole JSON/Unity authentication for a while
awesome post! thanks for sharing :)