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!
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; }.....
@@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)); }
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
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!
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.
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
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
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
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;
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
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;
}.....
@@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));
}
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.
well done!
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
Thank you so much! This tutorial was phenomenal. :D
thank you for watching!
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!
LOVE THIS tutorial! Very thorough and to-the-point!
thank you!
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
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!
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!
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.
Nice
thank you!
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
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
I assume you forgot or didn't want to add the scripts in the description :(
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?
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
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.
ummm some dungeon patterns are repeating like
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
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!