Roguelike - Template Rooms - Dungeon Generator (Beginner friendly tutorials inside!)

You want dungeons? Boy do we have dungeons for you!

Why would you want >my< dungeons? Well...

With this script, you can generate a dungeon of any number of rooms based on premade room templates you set up. Flashy, right? I figured we’d have quite a few dungeon rooms being made for this jam, and this generator (should) be cross compatible with all of them, any size, any shape.

I tried to make the process as simple as possible. Load up a template of a room you want to use, and put a RoomScript on it. Drag a trigger around it, set the RoomScript’s dimensions to be the same as the trigger, and drag in locators where the entrances are. The dungeon generator will do the rest for you. Any size or shape, big or small, this random generator loves them all.

I believe the easiest way to approach creating your own dungeons for games is to make the rooms, and then have a script handle the rest for you. Personally I could never wrap my head around maze based dungeon generators, or how to implement them in a meaningful way in a game. So I set out to make the dungeon generator that worked the way I thought about rooms and required the least amount of effort. I hope you feel I succeeded.


To learn how to set this up, I’ve recorded a tutorial of how to set up rooms from a template you’ve already acquired from the Community Tab, which is also where you’ll need to go to get this script. Forgive me as I’m not an experienced video maker, so the whole video’s maybe twice the length it needs to be, but it shows every step you need to do from right after importing a package to a generated dungeon.


Written Tutorial
If you prefer to read rather than listen to me ramble or see images, here’s how to set it up.

Step One

Acquire Package
  1. Go to the community tab.


forgive me for lying, this written tutorial also has pictures

  1. Search for Roguelike - Template Rooms - Dungeon Generator. Heck, you don’t even have to type the full name in, even just rogue will get you there. Then, click the Install button on the one you see below, circled in blue.

roguelike

It’s crucially important you press the button I’ve highlighted red, and also you can press the buttons highlighted green. I apologize if you’re red-green colorblind, I guess you’ll just have to press all three :stuck_out_tongue:

Congratulations! You have completed step one.

Step Two

Acquire Template(s)
  1. Look at the included assets, seen here in the packages tab.

Optional step: Try to drag things from there directly to the editor multiple times before you remember you can’t.

  1. Navigate to the template section on the left, it’s the one above the world icon and below the pin on a map icon (the locator icon, to be precise). You should see the various rooms included in the pack there now.

roomsz

  1. Drag them into the world to look at them in all their glory. Actually, we want to make sure they’re set up correctly.

Congratulations! You have completed step two.

Step Three

Setting Up Rooms
  1. Look at your hierarchy, it doesn’t matter which room. It’s okay if your hierarchy isn’t as empty as mine.

  2. The nESWRoom1 is one of the templates. Its icon is a pin, meaning it’s a Locator. A locator is an empty entity that doesn’t do anything but point to a place in space. But if you scroll down, you’ll see it has a script attached!

2a) If your locator doesn’t have a script there, time to add one. You can drag roomscript over to the hierarchy, or right click the locator to add it that way.

  1. You need to add a few things to the RoomScript for it to work, though the templates should be okay from the get go.

image

  1. First, drag each of your room locators into the entrances tab. These are the entrances to your room. If adjusting manually, place them somewhere like this in front of your door.

  1. Then, make a trigger that surrounds your entire room. Again, the templates already have this. You’ll have to adjust the Size settings to get it right. Take note of the first two values for your size.

  1. Back on our room script, we copy those two values in as our room dimensions.

image

Congratulations! You have completed step three, your room is set up.

Step Four

Setting Up Generator

We’re almost done. Hopefully this has been fairly painless, except for putting up with my humor. You’re stuck with me for another few steps.

  1. Create a Dungeon Creator. We need to make a new Locator, in order to do so you can do so from the world tree by right clicking and selecting a new Locator, or dragging one from the primitives menu on the left.

  1. You can rename it to something better, like, say, Dungeon Creator. Also make sure it’s set to 0, 0, 0.

image

  1. Just like before, we add a script to the locator. This time it’s named Dungeon Creator.
    image

  2. Drag your rooms you want to spawn from the template menu on the left into the Room Templates array.

  1. Set your Number of Rooms. The script will randomly pick between the left number and the right number to try to spawn. If you want it to be the same amount every time, put that amount in both fields.

5a) The minimum hall size will determine how spaced apart your rooms are.

5b) The maximum spawn distance prevents it from trying to spawn too far away.

5c) You can ignore the debug effect.

5d) Your settings could look like this:
image

  1. Click play!

Congratulations! You’ve done it!

My future plans for this is to put together a roguelike blueprint. You will be able to set different weights for the different types of rooms, and it will include scripts to manage spawning things in the rooms and preventing the player from leaving until they’ve cleared obstacles, like in games such as Binding of Isaac or Enter the Gungeon.

2 Likes