ROGUE LIKE RANDOM LEVEL GENERATION - INTERMEDIATE C#/UNITY TUTORIAL- #2

Поділитися
Вставка
  • Опубліковано 29 вер 2024

КОМЕНТАРІ • 113

  • @Blackthornprod
    @Blackthornprod  6 років тому +8

    In case you're worried in the next video we will be making sure that you can make different rooms within a same type :) ! So for example you'll be able to create as many left and right opening room templates as you like, and a random one from those will spawn when you want to spawn a left/right room. Same for all the other types of rooms !
    We'll also be making each room more unique by creating randomness withing a single room, and fill up the level with rooms outside of the critical path.
    + we'll fix that bug we noticed where sometimes there's dead ends when the level generator moves down twice in a row ! So stay tuned for episode 3 !

    • @useruser2676
      @useruser2676 6 років тому

      hi brother can you help me i make 2048 game and i want make partical system animatioo when i merge my tile can you help me and you do great job here on youtube you the best bro

    • @useruser2676
      @useruser2676 6 років тому

      i dont understand broother can you send e video

  • @alexanderbaron9778
    @alexanderbaron9778 6 років тому +19

    Great vid! I would suggest though to use enums instead of ints as the room type, as they are far easier to understand, simply because you can give them names. As they still have an int at their core, you can assign each enum value a custom number, making it very easy to change your current code. In fact, all you would have to do is to use (int) type instead of type.

  • @protagtom
    @protagtom 4 роки тому +4

    throws this: NullReferenceException: Object reference not set to an instance of an object
    the line of code it has a problem with: if (roomDetection.GetComponent().type !=1 && roomDetection.GetComponent().type != 3)

    • @beastbomber2316
      @beastbomber2316 4 роки тому +1

      Did you get fix it cause im having trouble with that also

    • @mmmyum4779
      @mmmyum4779 4 роки тому

      @@beastbomber2316 set room layermask to room 8:44

    • @protagtom
      @protagtom 4 роки тому

      @@mmmyum4779 did that. Still presisted.

    • @cunibon4395
      @cunibon4395 4 роки тому

      same problem here any ideas by now?

    • @neophyte4324
      @neophyte4324 4 роки тому

      Same problem had to restart but not fixed

  • @sergioteque3445
    @sergioteque3445 6 років тому +11

    You could instantiate the current room after you calculate the next direction instead of doing the circle thing
    PD: love your videos, keep up the good work

    • @AlphaTheMinerTheGameDesigner
      @AlphaTheMinerTheGameDesigner 5 років тому

      Please explain in detail, I am trying to convert the code over to a 3D project and it has gone so well up until this point... I dont know what to put, as collider2d obviously wont work for my 3D project.. Your solution seems like it could work exactly how i need it without the whole collider thing. I am at my wits end, please help! :

    • @AlphaTheMinerTheGameDesigner
      @AlphaTheMinerTheGameDesigner 5 років тому

      Collider2D roomDetection = Physics2D.OverlapCircle(transform.position, 1, room);
      if (roomDetection.GetComponent().type != 1 && roomDetection.GetComponent().type != 3) {
      roomDetection.GetComponent().RoomDestruction();
      int randBottomRoom = Random.Range(1, 4);
      if (randBottomRoom == 2) {
      randBottomRoom = 1;
      }
      Instantiate(rooms[randBottomRoom], transform.position, Quaternion.identity);
      }
      Vector3 newPos = new Vector3(transform.position.x, transform.position.y, transform.position.z - moveAmount);
      transform.position = newPos;
      int rand = Random.Range(2, 4);
      Instantiate(rooms[rand], transform.position, Quaternion.identity);
      direction = Random.Range(1, 6);
      }
      else {
      stopGeneration = true; // STOP GENERATING ROOMS
      }
      This is the code atm if you need it, naturally "Collider2D roomDetection = Physics2D.OverlapCircle(transform.position, 1, room);
      " wont work for my project but like i mentioned before i got no idea on what to do instead...

    • @robbieriot
      @robbieriot 4 роки тому

      My thoughts precisely ... like man he went into a lot of work for something he could have just changed the order instead of creating the room then moving, move then create the room.

    • @owentsai961
      @owentsai961 4 роки тому

      ​@@robbieriot Guess he's just doing it for demo purpose. If people are serious they could find tons of do-not-ever-do-this-in-your-code things in his script. No one will write a 100-line function or use int to indicate directions in real life.

  • @hamzahgamedev
    @hamzahgamedev 6 років тому +8

    If this is not inspiring, idk what is..!
    Good job, as always Noah! :)

  • @Aquarii_Z
    @Aquarii_Z 4 роки тому +4

    When my room spawner moves to the far left or right, it will sometimes stay there and instantiate another room on top of the first one before moving down

    • @stefan429
      @stefan429 4 роки тому +2

      if you or anyone else is still having this problem, you have to check the boundary AGAIN after rolling the new direction after moving the transform. you have to do this for each direction, left right and down. for example, for direction 1 or 2, i.e. moving right, the code becomes:
      _direction = Random.Range(1, 6); // prevent overlapping creations
      if (_direction == 3) // trying to move left
      {
      if (transform.position.x < maxX) // check if we are at bound again so we dont not move
      {
      _direction = 2; // we just came from left, so move right...
      }
      else
      {
      _direction = 5; // we are at the bound, so move down
      }
      }
      else if (_direction == 4)
      {
      _direction = 5; // ...or move down
      }

    • @dmencoStudio
      @dmencoStudio 3 роки тому

      @@stefan429 I couldn't fix it, can you send the script with the checks? I'm really grateful!

    • @ahsanzizan
      @ahsanzizan 3 роки тому

      @@dmencoStudio u can fix it by checking x transform position of ur first start pos then put in in minX and the 4th one then put it in maxX, and then check the bottom put it in minY

  • @CouchFerretmakesGames
    @CouchFerretmakesGames 6 років тому +4

    Pretty awesome, as usual! :)

    • @Blackthornprod
      @Blackthornprod  6 років тому +1

      Thanks :) !! I'm really glad you liked it :) !

  • @umbrason.
    @umbrason. 6 років тому +5

    can you do some turnbased stuff?

    • @Blackthornprod
      @Blackthornprod  6 років тому +3

      That could be very interesting :) ! I'll definitely think about it :) !

  • @waterfallbw
    @waterfallbw 6 років тому +6

    Blackthornprod: "Let's set a random number between 1 and 2" *types (1, 3)*
    My Brain *before realizing that that's the correct syntax* AAAAAAAHHHHHHHHH

    • @Blackthornprod
      @Blackthornprod  6 років тому

      HAHA ;D yeah it does sound a bit weird when I seem to type something completely different from what I say ! But yep, last number isn't included ;D !

    • @YuriNoirProductions
      @YuriNoirProductions 6 років тому +1

      except it is a float :|

  • @DJL3G3ND
    @DJL3G3ND 9 місяців тому +1

    thanks, couldnt directly follow along for much longer since I use unreal but even just episode 1 was enough to give me a good idea of what to do

  • @nandanvinjamury
    @nandanvinjamury 6 років тому +3

    Honestly, as an aspiring game dev, I get even more inspiration when someone younger than me is pushing content with knowledge that even I gain from every day. Thank you for these tutorials!

    • @Blackthornprod
      @Blackthornprod  6 років тому +3

      I'm so glad you like my content :) ! Your comment is a real motivation boost :) ! Cheers !

  • @Tal_Rumer
    @Tal_Rumer 6 років тому +1

    Feels like you are looking for overcomplicated ways of doing things /= Love your art though ❤️

  • @paulfnicholls
    @paulfnicholls 4 роки тому +1

    Would you have the compete source code I can look at somewhere? I found the video a bit quick to follow, but it was still informative :)

    • @izme3830
      @izme3830 3 роки тому

      look in the discription :)

  • @luciacover9909
    @luciacover9909 6 років тому +2

    This is a great video! Every video of yours gets better and better! Your tutorials are amazing! I love how they aren’t extremely long and bloated like most other tutorials!

    • @Blackthornprod
      @Blackthornprod  6 років тому +2

      Thanks for that kind comment :) , it's so appreciated! I do my best to teach fast and well, I definitely don't want to waste the viewers time :) !

  • @Coder420
    @Coder420 2 місяці тому

    for people who would have issue that rooms are disappearing if they re wrong and not being replaced, he emphasised the code what he was explaining but was prewritten so dont forget to include it after that if statement when room is not having opening on bottom : aka this part : int randBottomRoom = Random.Range(1,4);
    if(randBottomRoom ==2)
    {
    randBottomRoom =1;
    }
    Instantiate(rooms[randBottomRoom],transform.position,Quaternion.identity);

  • @chronoabi
    @chronoabi 4 роки тому +1

    I still have the same problem where the camera doesnt show the first room that spawns in the game please help me

    • @beastbomber2316
      @beastbomber2316 4 роки тому

      Move the camera to the spawn points xD or just go to scene mode afterr you press play

  • @n_th_n9228
    @n_th_n9228 6 років тому +2

    Amazing vid! Very informative, like always!
    Love everything that you post

    • @Blackthornprod
      @Blackthornprod  6 років тому

      Thanks :) ! It's a joy for me to make these videos ! I'm happy you like them :) !

  • @alindinca2864
    @alindinca2864 6 років тому +1

    Awesome as always :))) Keep making great tutorials and we'll deliver great games to the world.
    P.S.: We'll love if you're gonna make a tutorial about complex AI

    • @Blackthornprod
      @Blackthornprod  6 років тому +2

      Thanks mate :) ! I've made quite a few AI tutorials already (ranging from beginner to intermediate, check out my playlist on the topic and see if you find anything of interest there). I am planning on making AI tutorials where the characters react more to what the player is doing (which is sort of advanced ;D), stay tuned for that :) !

  • @niffnozzletoff4552
    @niffnozzletoff4552 5 років тому +1

    Hey Noah, great videos!
    I seem to be generating a double of the 'final room', and I can't really seem to figure out why. I have mine going from left to right, instead of top to bottom, but essentially if my room goes: up, right, right, down, right, it should end on the last room 'right' but it generates a second 'right' room before terminating. Any thoughts as to why?

    • @bilaljalook
      @bilaljalook 5 років тому

      I Have the exact same issue, did you by any chance figure it out?

    • @bilaljalook
      @bilaljalook 5 років тому

      nvm solved that, just needed to delete the Instantiate function at the of the whole method.

    • @beastbomber2316
      @beastbomber2316 4 роки тому

      @@bilaljalook please can you tell me what you did evan thoe this was 7 months ago

  • @waterfallbw
    @waterfallbw 6 років тому +1

    HOW AM I NOT FIRST
    i was waiting at discord for like 3 hours

    • @n_th_n9228
      @n_th_n9228 6 років тому

      His post in Discord was a bit late

  • @crazydev2084
    @crazydev2084 6 років тому +1

    You are the best I'm creating a game but I want to know how to build the .exe and the .apk how I can do this?

    • @umbrason.
      @umbrason. 6 років тому

      if you haven't done it yet, first set the "Bundle Identifier" (File>Build Settings...>Player Settings...>Other Settings), then go back to the Build Settings and hit "build" or "build and run", then choose a target location to save your game.now it should take a while and then you're done. For the apk its the same process but you have to set the target platform to a moblie device (also in Build Settings). @everyone else - Im also new to Unity so if im wrong please correct me.

  • @crazy_bro1239
    @crazy_bro1239 6 років тому +1

    What specs on a laptop do you think is needed to use unity to create programs like yours

    • @owenmp4
      @owenmp4 5 років тому +1

      I have a desktop, and in that there's 8GB of ram, a GTX 1060, a 3.7ghz 6 core processor, and it works just fine. Honestly, as long as you have a graphics card that is or is better than a 1050ti, a 4 core 3.5 ghz processor, and 8gigs of ram you should do alright. You could push it lower, but in benchmarks computers like that don't do too well. If you're looking for something just for 2d games, go right ahead and find something a bit lower if you want, but I greatly encourage you to save for a better computer. Trust me, it's worth it.

  • @c0d3r1f1c
    @c0d3r1f1c 2 роки тому

    I would suggest using a 2D array for the layout and then instantiating the rooms as a separate step.
    This would let you work with a simpler integer coordinate system during layout, just (0,0) to (3,3), instead of having to work in terms of the final float coords.

  • @jakubkadlec4285
    @jakubkadlec4285 4 роки тому

    ok .. really nice tutorial, nicely explained, but i would appreciate little bit of help. I'm trying to recreate this in 3d spacee and this line (Collider roomDetection = Physics.OverlapSphere(transform.position, 1, room);
    ) is creating error "type collider[] cannot be converted to collider" any help?

  • @cemalettincembelentepe8943
    @cemalettincembelentepe8943 5 років тому

    Wow, I would have never thought of that. I didn't have any idea that those methods was in unity. If you had ask me to somethink like that, I would have created a random maze creator (or in this case a maze generator to move down) and then creat the openings ect. Checking the above has opening with OverlapCircle ? Just use a 4x4 2D array and then check them... Btw this is not for discrediting this tutorial, on the contrary I am just astonished by it. wow...
    Note: I usally develop my game engines from scratch using Java w/Processing or C++. This is why I found this method so much incredible.

  • @p.y.tbasketball4434
    @p.y.tbasketball4434 4 роки тому

    NullReferenceException: Object reference not set to an instance of an object

  • @alexitosworld
    @alexitosworld 6 років тому

    I really recommend you to use enum instead of ints all over the place ;)
    Great video, now I want to do mazes for no reason :P

  • @koktszfung
    @koktszfung 6 років тому

    Could it be done like this: the type of the room is stored in a 1 dimensional array as the rooms are generating. The opening of a generated rooms were a number that is the product of prime number. If the number can be divided by say 2, it has a top opening. So after picking a position and before a room is generated, the room in its 4 direction was checked and see if there’s wall. If there’s wall, that room won’t have wall in that direction. Then with a completed array, we generate the actual room object.

  • @ordealofeligos3952
    @ordealofeligos3952 3 роки тому

    Woah! Did not know this is more efficient than the previous random level generation video.

  • @emirhurturk306
    @emirhurturk306 4 роки тому

    Great tutorial, but you were so fast that I needed to make playback time 0.75x. But a great tut!

  • @satirical_snake
    @satirical_snake 4 роки тому

    Hey! How would you go about doing this in 3D? I got stuck at the part where you have to use the OverlapCircle. I tried using OverlapSphere but there are some issues converting Collider to Collider[]
    Thanks

    • @NivekNKs
      @NivekNKs 4 роки тому +2

      If you still don't have the answer or for anyone who needs it, use a OverlapSphere like he said and define the Collider like this:
      Collider[] roomDetection = Physics.OverlapSphere(transform.position, 1f, room);
      Then in the if and everything else use this:
      roomDetection[0].GetComponent()
      This is working for me, I hope it works for you.
      PS: Probably the first part of the next tutorial won´t work like that so you can use this.
      public LevelGeneration levelGen;
      public bool hasRoom = false;
      void OnTriggerEnter()
      {
      hasRoom = true;
      }
      void Update()
      {
      if (hasRoom == false && levelGen.stopGeneration == true)
      {
      int rand = Random.Range(0, levelGen.rooms.Length);
      Instantiate(levelGen.rooms[rand], transform.position, Quaternion.identity);
      Destroy(gameObject);
      }
      }

    • @satirical_snake
      @satirical_snake 3 роки тому

      @@NivekNKs Finally got back on the roguelike project. Thanks for this, it really helped

  • @louisgjohnson
    @louisgjohnson 5 років тому

    you should just keep a list of positions where your rooms have been placed and then check the list before setting direction, the other logic seems a bit messy

  • @stefan429
    @stefan429 4 роки тому

    this is a fun series so far, has more explanation than some others on youtube, and you also secretly taught us the good practice of taking the room generation slowly by making them every half second. otherwise, you wouldnt have found half the issues you did (at least not as quickly) if the map was made instantly

  • @JM-dc5rn
    @JM-dc5rn 5 років тому

    If anyone has issues using the layermask method. I suggest using two references to the current room to be made and the previous made one. Seems to be a lot easier to work with when trying to make sure both rooms have an entry and exit. Can see it being more flexible in future too if you want to have a specific entry and exit have a certain mechanic that works together.

  • @thibulle9611
    @thibulle9611 5 років тому

    I can't insert a script in my prefabs anyone know why ?

  • @HelpingPanda
    @HelpingPanda 6 років тому

    Awesome tutorial! Just a tip regarding the part where you set the parent of the spawned objects, unity (kinda recently) added the function to set the parent directly in the instatiation. So after setting the rotation, just add a , transform. :)

  • @yasman405
    @yasman405 6 років тому +1

    Regarder tes vidéos me rappellent le lycée merci noah ^^

    • @Blackthornprod
      @Blackthornprod  6 років тому

      HAHA super :) ! Tu t'appelles comment :) ?

    • @yasman405
      @yasman405 6 років тому

      @@Blackthornprod Yassine ^^

    • @yasman405
      @yasman405 6 років тому

      Gab m'a dit que tu allais bien :)

  • @iitzniiko2803
    @iitzniiko2803 4 роки тому

    Yea I can’t figure out what I didint do right

  • @govindsuthar5882
    @govindsuthar5882 6 років тому

    Please make a video of sprite disintegration using unity

  • @darwin6755
    @darwin6755 5 років тому

    Thank you so much for this tutorial! I was really struggling to make one of these and then I found your channel. I love it so much!

  • @ir3dygames968
    @ir3dygames968 5 років тому

    Edit: Never Mind... Moved my border all is good!
    Original:
    Following a long but still spawning outside my border which is 4x4 like yours or is suppose to be 5x5? I'm lost alittle

  • @azain47
    @azain47 4 роки тому

    This is such a nice level generation series ❤️🙌
    Also I was thinking, any way we can make this script work in editor mode, like not when we're playing the game, but in editor when we just want to create some levels but too lazy to make them?

    • @hirashi
      @hirashi 4 роки тому

      Just put this:
      [ExecuteInEditMode]
      in front of the levelGenerator class

  • @simoncodrington
    @simoncodrington 6 років тому

    Another good video mate, thanks for all the great content you've been making 🎮🕹️
    Another way I've found when randomly generating levels is to keep the previous position and check it next time to make sure you're not moving backwards 👌

    • @Blackthornprod
      @Blackthornprod  6 років тому

      Thanks Simon :) !!
      Good point, a lot of people have mentionned that in the comments ! I guess it would of been more simple rather than using Overlap Circle and destroying the room :) !

  • @epicgamerman2510
    @epicgamerman2510 6 років тому

    Love your style! You are always so clear in what you say. Thank you, as all your videos have really helped me learn and grow as a novice level game dev!
    And also, if I may ask, where are you from?
    Edit: Also 87 like lol

    • @Blackthornprod
      @Blackthornprod  6 років тому

      Thanks mate :) ! That's really appreciated :) !
      I'm from France, with a scottish mum and english/french dad + an italian grandad, so quite a mix ;D !

  • @pannukakku4168
    @pannukakku4168 6 років тому +2

    You're slowly turning into Edmund McMillan

  • @ow887
    @ow887 6 років тому +1

    Keep up the great work dude

    • @Blackthornprod
      @Blackthornprod  6 років тому

      Thanks Owen :) ! I definitely intend to keep it up :) !

  • @mahmoud-quran
    @mahmoud-quran 6 років тому

    Kinda early

  • @dj2460
    @dj2460 5 років тому

    Great tutorial series.

  • @YannPicardFX
    @YannPicardFX 5 років тому

    est-tu francais?

  • @govindsuthar5882
    @govindsuthar5882 6 років тому

    Tnx for making

  • @J4P1T0L3
    @J4P1T0L3 6 років тому

    why u so sad?

  • @Steve-hq1tt
    @Steve-hq1tt 6 років тому

    Awesome!

  • @takedowngames4486
    @takedowngames4486 6 років тому

    50th

  • @XNeros96X
    @XNeros96X 5 років тому +1

    stopGeneration == false :'( you can do it like so " !stopGeneration "

  • @RatoCavernaBR
    @RatoCavernaBR 6 років тому +3

    Today is elections on Brazil, wish us good lucky in order to get a good man in the power.

  • @govindsuthar5882
    @govindsuthar5882 6 років тому

    Great works

    • @Blackthornprod
      @Blackthornprod  6 років тому

      No problem :) ! I'm glad you liked the video !

  • @PxlDev
    @PxlDev 4 роки тому

    1:15 random number between 1 and 3 you mean?

  • @AgeRestrictTheInternet
    @AgeRestrictTheInternet 6 років тому

    love you booboo, this material helped me with other problems I was trying to solve unrelated to random level generation :D