Unity Tutorial: ROGUELIKE Room / Dungeon Generation (Like the Binding of Isaac)

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 พ.ย. 2024

ความคิดเห็น • 57

  • @matthieuboissel3676
    @matthieuboissel3676 8 หลายเดือนก่อน +9

    Hey! Great tutorial!
    Just want to post my solutions for the two problems i can see in your system.
    1) The room overlapping
    Put this check in the TryGenerateRoomFunction :
    if (_roomGrid[x, y] != 0)
    return false;
    2)The error when a room tries to be created outside of the grid
    Put this check also in the TryGenerateRoom function (put it before all the other checks by the way) :
    if (x >= gridSizeX || y >= gridSizeY || x < 0 || y < 0)
    return false;
    Hope this helps anyone!

    • @rootbindev
      @rootbindev  8 หลายเดือนก่อน

      Thank you

    • @ke77i
      @ke77i 7 หลายเดือนก่อน

      when you fix the overlapping the first room never spawns with any doors

    • @bloodartist5235
      @bloodartist5235 3 หลายเดือนก่อน

      A moins que j'aille mis a la mauvaise place la solution pour out of grid ne semble pas fonctionner, l'erreur apparait toujours (et mon debug n'apparait pas)
      Voila mon code si jamais;
      private bool TryGenerateRoom(Vector2Int roomIndex)
      {
      int x = roomIndex.x;
      int y = roomIndex.y;
      if (x >= gridSizeX || y >= gridSizeY || x < 0 || y < 0)
      {
      Debug.Log("Out of grid cancel that s***");
      return false;
      }.....

    • @FennrirWolf
      @FennrirWolf หลายเดือนก่อน +1

      @@ke77i I posted a solution in a reply further down. Here is a copy of that post, hope it helps.
      "I also noticed this same issue. It is pretty far and few between, and also as Reece mentioned it is usually an overlap on top of the starting room. Rarer occasions do include non-starting rooms overlapping too. I'm not sure if this is the most efficient fix, but in our Update when we call the TryGenerateRoom 4 time, I added checks for neighbors prior to actually generating in any direction. I have not seen any overlap since I added these checks."
      if (gridX > 0 && roomGrid[gridX - 1, gridY] == 0)
      {
      //No neighbor to the left
      TryGenerateRoom(new Vector2Int(gridX - 1, gridY));
      }
      if (gridX < gridSizeX - 1 && roomGrid[gridX + 1, gridY] == 0)
      {
      //No neighbor to the right
      TryGenerateRoom(new Vector2Int(gridX + 1, gridY));
      }
      if (gridY > 0 && roomGrid[gridX, gridY - 1] == 0)
      {
      //No neighbor below
      TryGenerateRoom(new Vector2Int(gridX, gridY - 1));
      }
      if (gridY < gridSizeY - 1 && roomGrid[gridX, gridY + 1] == 0)
      {
      //No neighbor above
      TryGenerateRoom(new Vector2Int(gridX, gridY + 1));
      }

  • @scroll-anarchy8
    @scroll-anarchy8 4 หลายเดือนก่อน +4

    god damn, that was a dousey. I managed to follow along and got it to work like yours, but now I'm exhausted. Much appreciated, liked and subed.

    • @rootbindev
      @rootbindev  4 หลายเดือนก่อน

      well done!

  • @picatsso6721
    @picatsso6721 10 หลายเดือนก่อน +2

    Everything works just fine! Great tutorial!
    I'd like to see you explain how to spawn a boss room, a shop, secret rooms, like in Isaac!

    • @rootbindev
      @rootbindev  10 หลายเดือนก่อน +2

      I'm glad you liked it! I might do that in the future!

    • @picatsso6721
      @picatsso6721 10 หลายเดือนก่อน

      Oh, by the way, I just did it myself, with help of ChatGPT, now it's perfect: Boss Room is always has a connection to only one room and is always the furthest room from the start, also Treasure room and Shop room generating with only one room adjacent to them. It is still based on your code, just saying, if you are interested to see how AI implemented this - let me know.@@rootbindev

  • @The_Littlest_Cabbage
    @The_Littlest_Cabbage 8 วันที่ผ่านมา

    Thank you so much! This tutorial was phenomenal. :D

    • @rootbindev
      @rootbindev  8 วันที่ผ่านมา +1

      thank you for watching!

  • @FennrirWolf
    @FennrirWolf 11 หลายเดือนก่อน

    Great tutorial! One of the better, well explained ones I have seen on this topic. Would love to see more on this series for sure!

    • @rootbindev
      @rootbindev  11 หลายเดือนก่อน

      Thank you very much!

  • @LizzySphinx
    @LizzySphinx ปีที่แล้ว +5

    LOVE THIS tutorial! Very thorough and to-the-point!

  • @PaniniDev
    @PaniniDev 10 หลายเดือนก่อน +2

    AHHH Root how did I miss this upload of yours. I have always had notifs on D: Nonetheless, very organized tutorial!!

    • @rootbindev
      @rootbindev  10 หลายเดือนก่อน +1

      Thank you Panini! :D

  • @littlenugget4711
    @littlenugget4711 7 หลายเดือนก่อน

    Hey, awesome tutorial! I'm currently making a game for my school's game jam, and this helped soooo much. Thank you!

    • @rootbindev
      @rootbindev  7 หลายเดือนก่อน

      Thank you, and Good luck with the game jam!

  • @jakesmith4932
    @jakesmith4932 หลายเดือนก่อน

    Great guide! got it all working just from the video with minor fixes due to my own errors. I was curious on how one would go about placing the floor and prefabs of items in these rooms as they're being generated, as well as enemy spawning. I'm not sure if you have a video on that already but I'm trying to make a rogue like and this was really useful nonetheless!

    • @rootbindev
      @rootbindev  หลายเดือนก่อน

      thank you! there are many ways to do that, I would probably have some kind of trigger when the player enters the room, and in that case spawn the enemies. you can add more things to the room prefab such as enemy spawn points, a script to hold different kind of enemies, items, etc. then when player enters room (hits a trigger collider or something), then spawn some stuff.

  • @RG-vv4wcRG
    @RG-vv4wcRG 11 หลายเดือนก่อน +2

    Nice

  • @migalesch1839
    @migalesch1839 9 หลายเดือนก่อน +1

    thank you!

  • @ItsReece2
    @ItsReece2 ปีที่แล้ว +2

    This tutorial is great, well done and keep it up!
    I did notice that some of the rooms do overlap on top of each other during runtime. Do you know why?

    • @rootbindev
      @rootbindev  ปีที่แล้ว

      Did you follow the tutorial 100%? In my game, using this code I get no overlaps

    • @ItsReece2
      @ItsReece2 ปีที่แล้ว +2

      Yes, I did follow it but might be possible I missed something in the tutorial. I must say it's very uncommon it happens the overlap; normally overlaps from starting room and occasionally another room from the neighbouring nodes. @@rootbindev

    • @FennrirWolf
      @FennrirWolf 11 หลายเดือนก่อน +3

      I also noticed this same issue. It is pretty far and few between, and also as Reece mentioned it is usually an overlap on top of the starting room. Rarer occasions do include non-starting rooms overlapping too. I'm not sure if this is the most efficient fix, but in our Update when we call the TryGenerateRoom 4 time, I added checks for neighbors prior to actually generating in any direction. I have not seen any overlap since I added these checks.
      if (gridX > 0 && roomGrid[gridX - 1, gridY] == 0)
      {
      //No neighbor to the left
      TryGenerateRoom(new Vector2Int(gridX - 1, gridY));
      }
      if (gridX < gridSizeX - 1 && roomGrid[gridX + 1, gridY] == 0)
      {
      //No neighbor to the right
      TryGenerateRoom(new Vector2Int(gridX + 1, gridY));
      }
      if (gridY > 0 && roomGrid[gridX, gridY - 1] == 0)
      {
      //No neighbor below
      TryGenerateRoom(new Vector2Int(gridX, gridY - 1));
      }
      if (gridY < gridSizeY - 1 && roomGrid[gridX, gridY + 1] == 0)
      {
      //No neighbor above
      TryGenerateRoom(new Vector2Int(gridX, gridY + 1));
      }
      @@rootbindev

    • @bsdrago
      @bsdrago 9 หลายเดือนก่อน +1

      @@rootbindev I have the same problem, and you can see the problem in your video too (eg, 20:07). You can see 17 room created, but only "12" visible

    • @rootbindev
      @rootbindev  9 หลายเดือนก่อน +1

      Try adding the checks that @FennrirWolf posted above@@bsdrago

  • @rvlli2377
    @rvlli2377 4 หลายเดือนก่อน

    The camera in mine is square instead of rectangle but all of the settings are the same as what you have in the Inspector. What might need to be changed?
    edit: Found a solution: "By default, cameras will match the shape of your view in the Game window. To set it to the aspect ratio you want, go to the upper-left corner of the Game window, click "free aspect" and change it to the aspect ratio or resolution you want"
    In our case, I think it's 16:9

  • @MaximumSpice
    @MaximumSpice 9 หลายเดือนก่อน

    I assume you forgot or didn't want to add the scripts in the description :(

  • @rvlli2377
    @rvlli2377 4 หลายเดือนก่อน

    How would the code change if we were to want the walls of adjacent rooms to be the same wall rather than having space in between the rooms?

    • @bixarrio5251
      @bixarrio5251 4 หลายเดือนก่อน +2

      Change roomWidth to 17 and roomHeight to 9. The grid cells will then be the exact size of the room and the walls will lie on top of each other to make it look like they're the same wall

  • @SurvivalGamingyt
    @SurvivalGamingyt 9 หลายเดือนก่อน

    Would this also work with tilemap based rooms?

    • @AvoDev
      @AvoDev 8 หลายเดือนก่อน

      yeah, I was able to do it with minimal effort, just create a tilemap grid on the room object, and give it some colliders.

  • @codered_dev2
    @codered_dev2 7 หลายเดือนก่อน

    ummm some dungeon patterns are repeating like

  • @migalesch1839
    @migalesch1839 9 หลายเดือนก่อน

    Sometimes rooms are generating inside of existing rooms, any idea how to fix this?

    • @rootbindev
      @rootbindev  8 หลายเดือนก่อน

      I've noticed as some guys told me below, I'm not sure why

  • @MrBerfayHunalp
    @MrBerfayHunalp 10 หลายเดือนก่อน +1

    where are the scripts

    • @rootbindev
      @rootbindev  10 หลายเดือนก่อน

      I can send them at discord

  • @Arcann_bhp
    @Arcann_bhp 10 หลายเดือนก่อน

    Does this work with tiles?

    • @rootbindev
      @rootbindev  10 หลายเดือนก่อน

      I haven't tried it but it should work

    • @Arcann_bhp
      @Arcann_bhp 10 หลายเดือนก่อน +1

      @@rootbindevalso how can you edit the room like as content, if there’s only one prefab how can you make different type of rooms

    • @rootbindev
      @rootbindev  10 หลายเดือนก่อน

      Make another room prefab that suits your needs, and before instantiating the room you decide which prefab to Instantiate :) @@Arcann_bhp

    • @Arcann_bhp
      @Arcann_bhp 10 หลายเดือนก่อน

      @@rootbindev so I can just make a list of room and then randomize with the length of the rooms?

    • @rootbindev
      @rootbindev  10 หลายเดือนก่อน

      Exactly! Atleast that's how I would do @@Arcann_bhp

  • @LogicStudios_1
    @LogicStudios_1 7 หลายเดือนก่อน +3

    Great tutorial, how would I go about instantiating something at the last room generated...
    Edit: Figured it out.
    Add this code where you set generationComplete = true.
    GameObject lastRoom = roomObjects.Last();
    Instantiate(boss, lastRoom.transform.position, Quaternion.identity);
    Make sure your script is using System.Linq;

    • @rootbindev
      @rootbindev  7 หลายเดือนก่อน

      Thank you for sharing!