Search Unity

Need help connecting rooms in a procedurally generated dungeon

Discussion in 'World Building' started by voraggoulking, Jan 22, 2019.

  1. voraggoulking

    voraggoulking

    Joined:
    Nov 1, 2017
    Posts:
    3
    Hi all,

    I have a dungeon layout that I have procedurally generated. It is currently made up of empty boxes (technically: Bounds). What I am now trying to do is create the actual rooms that they represent and join them together in some way. I'm not sure on the best approach I should take with this. I have had several ideas but I was hoping someone might have some experience on the subject and give me some pointers.

    What I've tried/theorized:
    • Spawning one of several pre-created rooms in each box then try to link them up. The problem here is that I'm having trouble joining them up afterwards. They're not on any form of grid so getting corridors to line up is really hard. I've made several attempts at joining them but not sure if they're all that good or not.
      • Because they are random I can't rely on the doors opening straight into each other.
      • I have tried to create corridors between the different doors but I'm having trouble getting them to link up.
      • I am currently looking at creating a corridor that would wind around the rooms and try to bounce between the different doors.
    • Another thought I had was to custom build each room and engineer it so that each room would have a doorway that led into the rooms around it (some of them would have corridors if they were too far away.) . The problem here is that creating rooms in this manner seems inefficient and would probably not lead to very good looking rooms.

    Below is an example of how the layout might look: shown from the top. I only ran a small size for example purposes.
    ExampleLayout.png

    Any help or suggestions would be much appreciated.

    Thanks in advance:
    Tom
     
  2. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    I'd try and setup some kind of grid - perhaps every X units is a "tile" of the grid right. Then you can have different sized prefabs that will fit certain dimensions, and program a way to instantiate the proper prefab with the right rotation, and that would simplify things.

    Even using a very detailed grid (say, every 0.25 units is a tile) you would save a lot of complexity versus trying to generate a mesh and setup UV's properly with a tool, which can get quite tricky.
     
    JoeStrout likes this.
  3. voraggoulking

    voraggoulking

    Joined:
    Nov 1, 2017
    Posts:
    3
    Thanks for your reply.
    I hadn't really considered that before, it's an interesting idea, I'll give it some thought. That would make lining the rooms up far easier but I'm still not sure how I would go about connecting rooms that are a not as close to each other. I'm not sure if I'm just not understanding something but I'm having trouble navigating between vectors in 3D space. Even telling if a door is to the left or right or straight ahead of another door and then is that on the X or Z plane? etc. I'm fairly new to Unity and I've only been self taught.
     
  4. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    The way you connect the rooms depends I suppose entirely on your games design and the way the models are created. If you have a set of like 20-50 room prefabs, in various sizes, and have some setup with a door to the positive Z direction, some with another door also in the negative Z direction - then you know when your generating, that if your two rooms are "connected" on Z, the further negative room could use the single door on positive Z, while the second room might have the second prefab that had doors on both sides of Z. And this pattern gets very complex, like if your rooms connect in 3 or more directions, you need to consider that, and select the right prefab.

    If you need to connect distant rooms without just making more rooms, you could have another prefab (or set of prefabs) that are hallways/outside/whatever and also let the characters pass through. It all gets very specific to your game and your games requirements.
     
  5. voraggoulking

    voraggoulking

    Joined:
    Nov 1, 2017
    Posts:
    3
    Thanks for your suggestions, I haven't had a chance to try out the grid yet so I'll give that go and see what I can do.
     
    MD_Reptile likes this.
  6. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    Good luck!
     
    voraggoulking likes this.