Unity Tutorial: ROGUELIKE Room / Dungeon Generation (Like the Binding of Isaac)
Вставка
- Опубліковано 30 тра 2024
- Tutorial on how to make roguelike rooms and doors generation in Unity, like it's done in the binding of isaac.
Scripts coming soon.
Join the discord server: / discord
0:00 Setup Unity Scene
4:42 Coding "Room" script
6:14 Coding "RoomManager" script
20:15 Make rooms spawn randomly
21:49 Adjacent Rooms logic
25:00 Open Doors
35:06 Outro
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!
Thank you
when you fix the overlapping the first room never spawns with any doors
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!
Thank you very much!
Great video, please continue!
Adding a few timestamps/chapters to videos as long as this one could be nice, just a thought. But good job, mate!
Hey, awesome tutorial! I'm currently making a game for my school's game jam, and this helped soooo much. Thank you!
Thank you, and Good luck with the game jam!
AHHH Root how did I miss this upload of yours. I have always had notifs on D: Nonetheless, very organized tutorial!!
Thank you Panini! :D
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!
I'm glad you liked it! I might do that in the future!
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
LOVE THIS tutorial! Very thorough and to-the-point!
thank you!
thank you!
I assume you forgot or didn't want to add the scripts in the description :(
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?
Did you follow the tutorial 100%? In my game, using this code I get no overlaps
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
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
@@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
Try adding the checks that @FennrirWolf posted above@@bsdrago
Nice
Would this also work with tilemap based rooms?
yeah, I was able to do it with minimal effort, just create a tilemap grid on the room object, and give it some colliders.
Sometimes rooms are generating inside of existing rooms, any idea how to fix this?
I've noticed as some guys told me below, I'm not sure why
ummm some dungeon patterns are repeating like
where are the scripts
I can send them at discord
Does this work with tiles?
I haven't tried it but it should work
@@rootbindevalso how can you edit the room like as content, if there’s only one prefab how can you make different type of rooms
Make another room prefab that suits your needs, and before instantiating the room you decide which prefab to Instantiate :) @@Arcann_bhp
@@rootbindev so I can just make a list of room and then randomize with the length of the rooms?
Exactly! Atleast that's how I would do @@Arcann_bhp
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;
Thank you for sharing!