RANDOM DUNGEON GENERATION - EASY UNITY TUTORIAL - #3

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome back to black thorn prod I'm Noah and this is the final episodes of the random dungeon generation tutorial series so far we have an almost working system that generates a cool random dungeon but it still has a few flaws such has occasional openings leading to the infinite scene space our goal in this video is to fix this quirk and also put into place a system that will give our dungeon an EXO room with that said let's begin so first of all I wanted to fix a little mistake I made in the previous video this piece of code checking whether the spawned variable of the object collided with is equal to false is it necessary and will be immediately removed leaving this will actually create a nasty bug where rooms will spawn on top of the entry room with that done let's fix the openings in our dungeon the reason we get these openings in the first place is because to spawn points collide with each other and neither has the time to spawn a room before it is destroyed to fix this all we must do is check whether what we have collided with has a spawned rule variable equal to false if it does and this spawn point also has a spawn variable equal to false then we must instantiate some wall that will block off any opening so I'll type in some comment underlining what we must do and then head over to my room template script and add a public game object variable called closed rules basically a wall with the size of a room guaranteeing that the player does not escape the dungeon now we can simply instantiate that cloth room in our room spawner script [Music] however when we press play we will be faced with a problem indeed our entry room gets clogged up in closed rooms the reason for this is because the entry room spawns four rooms at the same time and those four rooms all come with a spawn points that collide with each other at the center of the entry room since each spawn point has spawned equal to false this if statement will run true and Clawd rooms will spawn the easy fix to this is to add a spawn point at the middle of the entry room call it destroyer remove the room spawner scripts attached to it and drag and drop a new script on it's called destroyer this script will be very short it will simply destroy all game objects that collide with it now if we hit play things should be working smoothly all right now that all rooms are being set up nicely I wanted to point out that if you want a higher chance of a certain room spawning in your dungeon all you need to do is drag and drop it multiple times in your arrays all right with that all fixed let's get our exit room up and running to do so we're going to use lists which is basically a dynamic array in other words an array that can have elements be removed and added to it at runtime what we will do is have each room spawn and be added to a room's lists the last room to be added to our lists will be the exit room so let me head over to my room template script and create a public list of type game object called rooms I'll then create a new script called add room and drag and drop it on to every single one of my room prefabs and open up this scripts will add the spawned room to our rooms lists but first I need to grab a reference to my room template scripts so like I did in the previous video I'll new private variable of type room templates called templates and in my start function sets templates equal to the game object with a runes tag and more precisely the room template components attached to their objects and right below that line of codes I will type templates rooms add and in the parentheses States this dot game objects now each room will be added to the lists we can actually test this out by selecting our room templates game objects and hitting play and you'll see that each room is added to the lists let's now put this to good use and spawn a boss in the last room added to our lists I'll start by creating a public float variable in the room template script called wait time a private pool variable called spawned bus and a public game object named boss in my update function I'll then Crete and if statements and check whether my wait time is less or equal to zero if it is we will want to spawn the boss if not we will slowly decrease the wait time value the reason we will wait a little before defining the exit room and spawning the boss is because we need to be sure all rooms have been spawns once the wait is over however we will create a for loop and get this loop to run as long as our Inza variable I is less than the number of elements in our lists since this is a list and not an array we get the number of elements by using dot count and not dot length we will now check whether I is equal to the number of elements in our list minus one because remember lists start with an index of zero like arrays and if that statement returns true then we will instantiate our boss at the room of index eyes position in other words at the position of our last spawned room and with no rotation we of course do what bosses endlessly spawning so our set spawned boss equal to true and add to my if statement up here the condition that spawned boss must be equal to false now the court in here will no longer run and so extra bosses will not appear in our game if I now type in a wait time of say two seconds to be on the safe side and drag and drop my simple boss sprites I can then press play and enjoy the site of my dungeon creating itself before my very eyes boss room and all before wrapping up the video let's do some optimization I'll head over to my room spawner scripts create a new public float variable called wait time with a default value of four and then in my start function destroy the game object with this script attached to it in other words my spawn points after a certain amount of seconds so wait time this way my scene will not be cluttered with useless spawn points carrying colliders and rigid bodies that way down memory space and get things to lag and that will mark the end of this video and of the random dungeon generation miniseries of course you cannot expand on this simple system by figuring out ways to generate different sized rules or you could simply have a packet of fun throwing your player into this dungeon with each room spawning random monsters and items with that said don't hesitate to ask for help if for some unfortunate reason a bug B failure I will come to your age the fastest possible also don't forget to hit the like and subscribe buttons if you enjoyed the content and don't want to miss any future in-depth game dev videos alright have a great day stay tuned Cheers [Music]
Info
Channel: Blackthornprod
Views: 108,163
Rating: undefined out of 5
Keywords: blackthornprod, noa calice, unity, game dev, tutorial, random, dungeon, RANDOM DUNGEON GENERATION - EASY UNITY TUTORIAL - #3, episode 3, how to, make, create, generation, procedural, map, the binding of isaac, simple, basic, easy, beginner, rooms, collisions, randomized, spelunky, nuclear thrones, quick, programming, C#, run time, coding, #3, indie game dev
Id: CUdKdHmT8xA
Channel Id: undefined
Length: 8min 29sec (509 seconds)
Published: Mon Mar 19 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.