Stadia Name: Vilva#9953
Package Name: Dungeon Generator
Package Description: Generates a random dungeon layout of connected rooms.
Showcase Game: See Build Jam - ‘Dungeon Master’ - Dungeon Generator
Place the “DungeonGenerator” template in your game world.
- Connecting rooms on “Connector” Locators, instead of using a grid. We believe that this room based approach allows for much better artistic control.
- Automatically rotates rooms according to the “Connector” rotation.
- Supports blocking unused pathways.
- Includes checks to prevent room overlapping
- First we check if the directions of the connectors match (Vector dot product must be <= 0).
- Then we also check the bounding boxes of other rooms for overlaps. We only do this check if the squared vector distance of the two rooms is smaller than a threshold. This improves performance by a lot.
How it works
- The generator works by connecting rooms that both have a “Connector” locator with the same type. For example “B” Connectors can only connect to “B” connectors. Please have a look at the included “DungeonRoom” templates. It is also possible to have one room with multiple connectors of the same type.
- Important: Room templates must be centered correctly. This means the parent locators (Connectors, BoundingBoxes, SpawnPoints) must all be in the center of the room and at (0, 0, 0) coordinates.
- “DungeonObjects” can randomly spawn inside “SpawnPoints” of the room. “DungeonObjects” can be any template, examples are:
- Treasure Chests you can pick up
- Traps that kill the player
- Enemies that attack the player
How to add your own rooms
- Start with one of the “DungeonRoom” templates.
- Create a new template and add meshes or voxel meshes to build your room.
- After you are done with designing, make sure that the “BoundingBox” covers your whole room. If the room has a lot of corners you can also use multiple triggers.
- Add Connectors so that the room can connect to other rooms. Adjust the Connector types to your liking. Connectors must be outside of the “BoundingBox”.
Dungeon Generator - DungeonGenerator
- roomSpawnLocator <
entity> - Move this somewhere out of sight (e.g. below the map). We need this locator to spawn every room template once in the beginning.
- startingRoom <
entity> - You need to set a starting room. This can be any of the room templates or something unique.
- roomTemplates <
template> - A list of templates for all the dungeon rooms that can spawn.
- objectTemplates <
template> - A list of templates for all the objects that can spawn inside the dungeon rooms.
- numberOfRooms <
number> - Specifies how many rooms will be generated.
- preventSameRoomConnections <
boolean> - If checked the same room can’t connect with itself. Instead it will always connect to a different room.
- supportRotatedConnections <
boolean> - If checked rooms can spawn rotated, according to the global rotation of the connector entity they connect to.
- emptyObjectSpawnWeight <
number> - Increase this number to make it more likely to leave a spawn point empty.
- randomSeed <
number> - If you set a seed you will always get the same generated dungeon. This requires that the other properties didn’t change. Setting a value of 0 counts as no seed.
- destroyConnectorChildren <
boolean> - If checked children of used connection elements will be destroyed. This can be used to give the rooms a more natural look and block unused pathways.
- maxSquaredDistanceForOverlaps <
number> - Only check for overlaps with rooms that have a Vector.SquaredDistance of this or less. Try increasing this number if you encounter overlapping rooms.
- initialDelay <
number> - Wait with initializing until the basic game has loaded.
- delayBetweenRoomSpawns <
number> - When using bigger rooms it might be necessary to increase this delay.
- generateDungeonOnInit <
boolean> - Automatically generate the dungeon when the server starts.
- debugPrints <
boolean> - Prints some debug info.
Dungeon Rooms - DungeonRoomConfig
- roomName <
string> - The name of the room. Must be a unique string. Is not shown to the user.
- connectors <
entity> - Reference to the parent object of all room connectors. A room must have a minimum of 1 connector.
- boundingBoxes <
entity> - Reference to the parent object of all room boundingBoxes. BoundingBoxes prevent a room from spawning inside another room. It is therefore required to cover the whole room in a big trigger boundingBox (or multiple smaller ones).
- spawnPoints <
entity> - Reference to the parent object of all room spawnPoints. A room can have 0 spawnPoints.
Dungeon Connectors - DungeonConnectorConfig
- connectorType <
string> - The type of the connector (A, B, C, D in the example)
Dungeon Objects - DungeonObjectConfig
- spawnWeight <
number> - How likely this object is to spawn in relation to all other objects. Bigger spawnWeights are more likely to spawn.
Functions that can be called from outside the script
- DungeonGenerator:GenerateDungeonRooms() - Generate a new set of dungeon rooms.
- DungeonGenerator:DestroyDungeonRooms() - Destroy all generated dungeon rooms.