Procedural Generation - Separating Rooms


Every game with a dungeon needs a procedurally generated dungeon to be unique and replayable. A significant part I worked on in Slimegeon was a procedurally generated dungeon. To do this, I spawn Hierarchal Instanced Meshes at random locations with a randomly ranged size. Then I calculate connections to the rooms and map hallways between them. 

A significant issue began when I started implementing more functionality. Doors themselves were being spawned as instanced meshes as well. That meant I couldn't access the mesh and had to rework this feature. I also had no control over the separate rooms. There was no accessibility to when the player entered, how many enemies were in a room, or where to spawn specific items and models.

To combat my main issue, I decided to work with box collisions. I made a component on the dungeon that would spawn an actor called "RoomTrigger" in the stored center of a room. After, I calculated the min and max of the room. I subtracted the maximum from the center to get the extent. However, I also added a scaling feature to the meshes, so I had to add the multiple of the scale by the size of the mesh * 0.5. I then accessed the box collision and set the box extent to the calculated area. 

Having this done, I could create overlaps for all actors and components. 

First, I got all tile locations within the bounds and added them to an array on RoomTrigger. I also got the begin/exit overlap of the player and enemies. Using this, I could close all the doors when the player enters the room and open all doors when all enemies are defeated. For the future, I would take these into account while making the generator or item itself. I would think about what ways to make what I'm creating as versatile and reusable as possible.

Leave a comment

Log in with itch.io to leave a comment.