Procedural Dungeon Generator in Unity [EXTRAS]

Поделиться
HTML-код
  • Опубликовано: 5 авг 2024
  • In this tutorial we'll be taking a look at how to make our dungeon a little bit more interesting and a little bit more robust. We'll handle generating random rooms and also setting rules to make our procedurally generated dungeon in Unity a bit more orderly. This video is a second part to the first Procedural Dungeon Generator Tutorial that is listed down below.
    Code: github.com/silverlybee/dungeo...
    Procedural Dungeon Generator in Unity: • Procedural Dungeon Gen...
    Assets used in this video:
    Stylized Hand Painted Dungeon: assetstore.unity.com/packages...
    L2S ARTS: luther2s.artstation.com/
    ----
    TIMESTAMPS
    (00:00) Intro
    (00:24) Room Prefab
    (02:00) Overlapping walls
    (13:45) Generating Random Rooms
    (15:36) Rules for Generating Rooms
    (25:35) Outro
    ----
    SOCIAL MEDIA:
    - TWITTER - @SilverlyBee
    - INSTAGRAM - @SilverlyBee
  • НаукаНаука

Комментарии • 61

  • @rendfall
    @rendfall 2 года назад +5

    Brilliant tutorial! No bullshit just pure practical knowledge.
    I love that you don't skipping Unity UI stuffs like dragging and filling like in many others videos on youtube.

  • @ausername4meplease
    @ausername4meplease 3 месяца назад

    Love your solution! Very very helpful and powerful.

  • @pixelb0i255
    @pixelb0i255 2 года назад +6

    Most impressive implementation I’ve seen on random/ obligatory dungeon gen!!! Fantastic explanation and has tons of use cases. Thank you !

    • @SilverlyBee
      @SilverlyBee  2 года назад +1

      Thanks! Glad you liked it!

    • @pixelb0i255
      @pixelb0i255 2 года назад +1

      @@SilverlyBee the thanks is owed to you. I’m studying your code. Could apply it to random generation of items in rooms

    • @SilverlyBee
      @SilverlyBee  2 года назад +2

      @@pixelb0i255 Yeah, my advice to you would be to make the random generation of items/enemies be handled by the room itself and the maze script just handle a sort of seed or bias

    • @pixelb0i255
      @pixelb0i255 2 года назад +1

      @@SilverlyBee that make more sense. Thanks for the advice. I’ve added this frustum logic the disable rooms at a distance from camera. Again this has been the best implementation I’ve seen. Kudos

    • @pixelb0i255
      @pixelb0i255 2 года назад

      Is there a book you could recommend on DFS?

  • @valdirwilleneto1447
    @valdirwilleneto1447 2 года назад

    I love your tutorials. thanks

  • @Night-xn1ks
    @Night-xn1ks 2 года назад +2

    Very useful thank you!

  • @saqibbro5297
    @saqibbro5297 Год назад

    This is the most amazing video.

  • @nikaman9539
    @nikaman9539 Год назад

    Thank you soo much ! This is so coooool!

  • @victorbesa6121
    @victorbesa6121 2 года назад +7

    I still don't understand how to make a end room, for example, make the farthest room an exit room, or make the last room generated a exit room, ONLY ONE EXIT, and how do i make to random spawn a key for exit the dungeon? :/

  • @altoggiv737
    @altoggiv737 Год назад +4

    How should I go about adding a limit to how many rooms of a certain prefab can be generated? For example, only allow for 1 ending room? I can set it to the last generated room using the Rules class from this video but I'd like it to be able to spawn anywhere at random.
    EDIT: Nevenmind, figured something out myself. I wrote a bit of code that replaces an already generated room with a final room prefab. For those curious or in a similar situation, here's what I did:
    (I should probably mention that I did this without the whole rules system applied, but you can still do this with that system in place too)
    First, in the RoomBehavior script, I added a bool array named status. In the UpdateRoom function, which takes a bool array as a parameter of its own, i save this parameter in the newly added status field.
    In the DungeonGenerator script, I added a public GameObject field named finalRoom. In the inspector, you can add a room prefab you'd like to use as a final room.
    At the end of the GenerateDungeon function, I made a new List of type GameObject, and used a foreach statement to get all game objects attached to the child objects of the "Generator" object in the scene to this list. The children of this object are the generated rooms.
    Then, I create a var replacedRoom, which I set to a random child of that list with List[Random.Range(1, List.Count)]. I set this minimum random range to 1 so that I don't replace the players spawn area.
    (If you don't want your final room to replace a random room, but the last generated room, then set replacedRoom to List[List.Count - 1])
    I then instantiate a GameObject using Instantiate(finalRoom, replacedRoom.transform.position, Quaternion.identity, transform). This puts your final room at the location of the room you're replacing.
    This is followed by calling the UpdateRoom function of the final room, but for the parameter, I use the new status field of the replacedRoom. This sets the right walls and entrances for the neighbors.
    Finally, I destroy the replacedRoom object, so that the final room isn't clipping into this room.

    • @rmt3589
      @rmt3589 Год назад +1

      Thank you for sharing this!

    • @altoggiv737
      @altoggiv737 Год назад +1

      @@rmt3589 Glad to help haha

  • @surtymir
    @surtymir 8 месяцев назад +1

    Your two videos on the subject are great. Super explained, thank you very much!
    Is it possible to continue the whole thing? Also with rooms/corridors of different sizes and with several floors?

  • @EnginesofHopeTheLastRefu-km2wy
    @EnginesofHopeTheLastRefu-km2wy 7 месяцев назад

    A good follow up would be a save system for this dungeon. Everytime we start the scene we get a new dungeon. Would be neat to save the seed and load back up on the same seed/dungeon.

  • @Taobyby
    @Taobyby 2 года назад

    Big thanks for your video. It helped me a lot to understand the algorithm. Maybe you could try to increase the time you show * comments in the video. It feels like a fight club single frame splice :)

  • @comradelmo2782
    @comradelmo2782 Год назад

    Hi, how would I get around doing a ending room which needs to be at the very end of every dungeon obligatory?

  • @RealityScapeStudios
    @RealityScapeStudios 2 года назад +1

    Ok so I've been using this one for a while but I noticed most of the time it's a straightforward path. How can we make this a bit more of a maze with more openings in each room? Most of my rooms have one room opening meaning its easy to get out or find the end of the path.

  • @charlestheninja
    @charlestheninja 2 года назад

    Really cool approach! But currently the dungeon starts at bottom left and aways end at top right. Would it be possible for the dugeon starts at the center ,and from this center room it grows to all directions?

  • @SOSmysteries
    @SOSmysteries Год назад

    Hi I am having trouble with this where the doors are not appearing inside only on the outside, and also the open doors are not completely connected to the walls...any ideas?

  • @mikehowlington4020
    @mikehowlington4020 2 года назад +4

    Hey I have a question , how could I mix different size rooms , if i try to add them to the generator they simply overlap :(

    • @AlekseyOnelin
      @AlekseyOnelin 5 месяцев назад

      my best guess is when you choose that specific room you change the grid, and when it changes to another one, you change the grid to its according size. i havent done this yet, thanks for the idea though!

    • @AlekseyOnelin
      @AlekseyOnelin 5 месяцев назад

      i tested it out and it works

  • @davestomper3428
    @davestomper3428 2 года назад +2

    Wow, this is really good information Sylvia thanks for doing this you are so detailed. I have a couple of questions though could you use this to create randomly sized rooms? Also, say you make a level 2 door and you go through it will it generate a new level the way the code is written or is there something else that needs to be done? If you go through level 1 and enter level 2 and fight creatures then you go back through the door into level 1 will this be a new level or will it be the same level 1 as before? When you researched doing this video did you find any good links you can share? Any chance you can share a link to the code ?

    • @SilverlyBee
      @SilverlyBee  2 года назад

      You could adapt this code to generate rooms with varying sizes but I don't think it would be the best algorithm for it. If you call the function to generate the rooms it will generate a new pattern so you could call the function to generate a 2nd level. If you changed scenes you'd have to save the state of level 1 first before going back. You could look at random generation using seeds if you just want to maintain the same rooms/disposition, but it wouldn't save the state of each room (if the player killed the enemies, what they dropped etc). If you don't change scenes and just instantiate a level 2 (without overriding level 1) then it would be there. I forgot to post the link to the code, I have updated the description with it now. For this video, since I was going for a simpler algorithm I searched for "maze algorithms" mainly.

  • @thebigs1997
    @thebigs1997 Год назад +1

    some times it doesnt spawn "boss room" even when its bligatory = true, how can i fix this?

  • @snakeywakey4109
    @snakeywakey4109 5 месяцев назад

    Hello! i have an issue regarding the performance of the dungeon, it appears that unity doesnt support dynamic occlusion culling out the box and its causing quite the performance drop by rendering objects through walls, do you have any solutions?

  • @LirusNeon
    @LirusNeon 3 месяца назад

    How do i make sometimes dungeon generate more than 1 door?
    always are 2 doors

  • @Kentalian
    @Kentalian 2 года назад +1

    Great followup! Just wondering, you mentioned using a 5 bit binary number for the cells in the level generator. Is there a tutorial on this somewhere? I'm not quite sure where to start on that.

    • @SilverlyBee
      @SilverlyBee  2 года назад +2

      Thanks! I haven't found a tutorial that covers this exact topic on C# but in this one: ruclips.net/video/Y37-gB83HKE/видео.html is in C++

    • @Kentalian
      @Kentalian 2 года назад +1

      @@SilverlyBee Thank you!

  • @RedthrowerGames
    @RedthrowerGames 8 месяцев назад

    Is it possible to get the seed of the generated map or input a seed of the dungeons?

  • @samerkia
    @samerkia Год назад +4

    Hello, can the random rooms be of various sizes? I created a second room twice as big as the first room we made in the tutorial, I tried fiddling around in the code but can't figure it out, every time the second room is generated it acts as a normal room and clips into other rooms.

    • @alroyfernandes4090
      @alroyfernandes4090 Год назад

      I wanted different corridors for my Boss Room so I was facing the same problem, the issue was that the pivot point on my door was in the centre of the room and not on the door so the collider could not detect the next room simply fix the pivot points on your objects and make sure the object you are trying to detect is within the radius of the overlap sphere

  • @isaackleinman9690
    @isaackleinman9690 2 года назад +1

    Just finished watching, great video, however I am a bit confused on how the min and max position works in terms of placing the rooms are you able to explain it a bit please? like how does the x and y of the min position equivilate where the room will be placed? same as the max position, thank you!

    • @alroyfernandes4090
      @alroyfernandes4090 Год назад

      if you set the grid size 5 X 5 you want to put your start room min at 0,0 and max at 0,0 for you boss room it should be min 4,4 and max 4,4 also the rooms at the top of the list will spawn at that pos

  • @kyojin_.
    @kyojin_. Месяц назад

    Hello! How could i add a player that could browse the dungeon?

  • @athier5898
    @athier5898 2 года назад +1

    great video, but think it would be helpful in the intro to see what you are going to be doing (ive noticed in your other videos that you dont do this) but just an idea :)

  • @floridaman1038
    @floridaman1038 7 месяцев назад

    Great tutorial, but do you know of a way to randomly add different sized rooms as well?

    • @Jaron-Wilson
      @Jaron-Wilson 6 месяцев назад

      That what I did from the start just change the offset! Hope this helps!

  • @neuroxcx1105
    @neuroxcx1105 Год назад

    how can i spawn enemies in the rooms?

  • @bigblue489
    @bigblue489 2 года назад

    Do you plan on doing a add on for addil floors? with stairs and such? or no. good guide tho!

    • @SilverlyBee
      @SilverlyBee  2 года назад +1

      I'm not sure if I get you. For this tutorial, this was the last part. I do intend to maybe in the future make a full blown dungeon crawler tutorial and use a different algorithm for generating the rooms maybe I'll get into generating different levels then. For this algorithm specifically, you could easily adapt it to 3D and make a 3D dungeon maze with different levels. The only changes would be the neighbors can now be north/south/west/east and up/down and you'd need a 3rd dimension for the levels.

  • @oliefb
    @oliefb 2 года назад

    Hey i've watched both tutorials, and for some reason i still got this "bug" on the project, all rooms generate in the same exact spot, i haven't figured out what is it yet, but could you give me a little hand?

    • @ythSnoozed
      @ythSnoozed Год назад

      Change the x and y offset in Dungeon Generator in inspector, these offsets depend on your asset/room.

  • @editzz4513
    @editzz4513 2 года назад

    Hello, I have an issue that, the collider is getting disabled in 1 side, but its still active in the other side... as a results my character cannot pass through it... The issue is with Down and Right doors... Any idea to fix that? On all doors i have the colliders and tag wall. In the UP/LEFT doors the colliders are disabled and they have the script. DOWN/RIGHT have only the collider active.

    • @editzz4513
      @editzz4513 2 года назад

      The only thing I didnt do from the video is to have the pillars, is that an issue?

    • @raidoukuzunoha9874
      @raidoukuzunoha9874 2 года назад

      @@editzz4513 'on all doors and walls', do u mean u tag 'wall' to the up, down, right, left doors and walls? if u tag wall to the right n bottom doors n walls, theres no need to tag wall to up n lefts'. Also if the door has a hole for player to move through, try using mesh collider instead of box collider. idk if this gonna help u or not. For the pillars, i think thats not the issue

  • @LRadyannStudio
    @LRadyannStudio 2 года назад

    Hi, please to make tutorial for the spawnpoint player in dungeon ?

    • @SilverlyBee
      @SilverlyBee  2 года назад

      Hey, currently I don't intend to expand on this tutorial. But maybe you could just make a room with the spawn point and put make a rule so it's on the 0,0 point

  • @escuelafacu2659
    @escuelafacu2659 2 года назад

    Hola excelente. Como pongo un cofre de tesoro en el último cuarto generado?

    • @SilverlyBee
      @SilverlyBee  2 года назад +1

      Hello, you can create a room with the treasure chest and set it as an obligatory spawn at the last room.

  • @mahimajain1119
    @mahimajain1119 2 года назад

    Hey how do I make the character move inside the dungeon? How do I make the walls solid so the player cant pass through them but can pass through the doors only. Really need help :/ P.S. I'm a beginner with unity

    • @MrBanana12344
      @MrBanana12344 2 года назад

      She probably just put colliders on the walls but not the doors so the player will just walk through them.

  • @aliyo.1737
    @aliyo.1737 Год назад

    why does mine lags when i play

  • @KingDoogan
    @KingDoogan 2 года назад

    For 2D Rooms change the newRoom instantiate from (i * offset.x, 0, -j * offset.y) to (i * offset.y, -j * offset.y, 0)
    var newRoom = Instantiate(rooms[randomRoom].room, new Vector3(i * offset.y, -j * offset.y, 0), Quaternion.identity, transform).GetComponent();
    up or left & down or right. set 0 & 3 to false.
    board[currentCell].status[3] = false
    board[currentCell].status[0] = false
    ^Set those to false, to fix random missing walls in 2D