Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

2D Random Dungeon Generator

Discussion in 'Scripting' started by Paykoman, Nov 8, 2019.

  1. Paykoman

    Paykoman

    Joined:
    Jun 26, 2014
    Posts:
    500
    Hi guys, im trying to build a random 2D dungeon generator from diferente premade levels (tilemaps) but im not getting there anyway.. im kinda new to scripting and i try find some help but all tutorials and so are or for 3D or to create compact random dungeon maps not to simply randomize premade rooms...

    Any help will be welcome, cheers
     
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Where are you so far? Can you describe where you are stuck?

    Here's one simple idea that will not generate terribly interesting looking dungeons.

    Create your blocks so that they have knowledge of their directions that you have openings to. This could be the typical left to right, up to down, "+"-shape crossing, t-crossing and so on.
    Then start from a random or defined location, and get a random block that has at least one direction open. Next, process the directions that are open, and randomize a block to that location that has a matching opening. You have to of course set various rules to get your map water proof. But if you repeat that kind of logic, you would get a dungeon that is random.

    This is of course just the logic side of things. Then you would need to build a system that will combine your tile maps together into one tilemap.
     
    Last edited: Nov 9, 2019
  3. Paykoman

    Paykoman

    Joined:
    Jun 26, 2014
    Posts:
    500
    I try that method and it word if i use square rooms, with enter and exit center in square size, i just cant get it to connect them properly because i dont have the entrances and exits centered, because my rooms are not square, how can i define the points to conect? Create empty game objects with some kind of name that we use to conect? I cant get it to work anyway... and im a bit newbie.. sry for so many and crazy questions
     
  4. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @Paykoman

    Didn't you already ask this in 2D area?

    There you said you are using Tilemap based rooms.

    You could just do what I explained, get a room from room Tilemap, then store those as an array, then in your procedural generation script, use these room "blueprints" to create the rooms in your dungeon map.

    You'll eventually have to set tiles manually in code if you are doing procedural dungeon generation.

    I don't know if you can actually somehow merge two Tilemaps (this is what you asked in your other question), correct me if I'm wrong.

    To handle the connection points, you would now have room data, where you know that certain tile names are doors, which you can use as attachment points to create edges/connections between rooms (your nodes).
     
  5. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,469
  6. Emolk

    Emolk

    Joined:
    Feb 11, 2014
    Posts:
    241
  7. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,469
    It's just a tutorials to use the tilemap and introduce concept, if the algorithm is flawed, fix it.