Maze Generation Unity Tutorial

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

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

  • @_sandeepnambiar
    @_sandeepnambiar  4 ปีที่แล้ว +8

    I've uploaded all the source + assets to github. Here's the link -> github.com/gamedolphin/youtube_unity_maze

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

      How can I make the hallways wider?

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

      @@zmichael4114 You ever find out how to do it?
      Would be very helpful

  • @johnevangelou2521
    @johnevangelou2521 ปีที่แล้ว +12

    For anyone trying to add randomized exits to the maze, you can modify the 'Generate' method as follows: public static WallState[,] Generate(int width, int height){
    WallState[,] maze = new WallState[width, height];
    //Initially all the walls EXIST
    WallState initial = WallState.RIGHT | WallState.LEFT | WallState.UP |WallState.DOWN;
    for (int i=0; i< width; ++i){
    for (int j=0; j

  • @Adventures_of_YR
    @Adventures_of_YR 8 หลายเดือนก่อน +3

    Thanks for this. I really love it. Just note you have a bug in your code. If you increase the size of the wall, it doesn't properly handle the position anymore. All you have to do is change the following line: var position = new Vector3(-width / 2 + i, 0, -height / 2 + j);
    It should be: var position = new Vector3(-width / 2 + (i * size), 0, -height / 2 + (j * size));

  • @RealFakePhD
    @RealFakePhD 3 ปีที่แล้ว +15

    For those struggling with the scaling issue, you can adjust the scale using this script. It's more of a band-aid and not a proper fix. It may not be a good fix depending on what your game will be. Just make a script called MazeScaler and put it on your MazeRenderer game object. adjust the Scale setting to change the size, I use scale settings X:4 Y:9 Z:4
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class MazeScaler : MonoBehaviour
    {
    public float xScale;
    public float yScale;
    public float zScale;
    public void Start()
    {
    transform.localScale = new Vector3(xScale, yScale, zScale);
    }
    }

  • @CHKNSkratch
    @CHKNSkratch 3 ปีที่แล้ว +11

    way higher quality than expected for even channels with thousands of subs, you've earned a subscriber!
    edit: took me several hours due to interruptions and the fact that for some reason you can't have multiple objects in the prefab or it won't scale right. one eye is twitching but it's working.

  • @techsyndrome3291
    @techsyndrome3291 4 ปีที่แล้ว +3

    I really like how subtle the video went , AWESOME👍

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

    THANK YOU!! Your video saved my final project for a course!

    • @ahmadsalim246
      @ahmadsalim246 19 วันที่ผ่านมา

      i am also using it for my project but failed to generate maze, need help?

  • @mistermistah3380
    @mistermistah3380 2 ปีที่แล้ว

    I would add it to an action RPG. Enter say a cave and randomly generate a large maze inside inside of it. You have to enter a door to enter the maze and there will be a disclaimer outside that after X minutes inside, the door will lock. When it does the maze will fill with lava killing the player (or whatever death mechanic - maybe a Minotaur spawns and smites the player). The maze can be filled with various loot and the loot gets progressively better the deeper into the maze you go, but it also becomes more disorienting.

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

    THANKS NOW I CAN MAKE THE BACKROOMS :)

  • @nandita.nambiar
    @nandita.nambiar 4 ปีที่แล้ว +2

    Amazing video!! So informative

  • @domingodiazfestivo
    @domingodiazfestivo 4 ปีที่แล้ว +3

    Hey dude! Awesome tutorial! This is by far the one that was most useful to me. There was a part of the video in which you talked about a seed for generating the mazes and you never got to it :( Are you planning on making a video about that? If not, how could I generate a random seed at runtime? I'm kinda new to this and just can't get it to work. Thanks again for the tutorial, I learned a lot!I suscribed to the channel, and hope you upload more videos in the future, keep up the good work! :)

    • @_sandeepnambiar
      @_sandeepnambiar  4 ปีที่แล้ว +1

      Hey, sorry been a little busy. To make this deterministic, th-cam.com/video/ya1HyptE5uc/w-d-xo.html -> at this point, when creating the rng variable, replace the /*seed*/ comment with an integer value. Here's the system random class instantiation for reference - docs.microsoft.com/en-us/dotnet/api/system.random?view=netcore-3.1#Instantiate . This would generate the same maze every time.

    • @domingodiazfestivo
      @domingodiazfestivo 4 ปีที่แล้ว

      @@_sandeepnambiar hi! thanks for the reply, i had figured it ut already but the link you provided was very helpful too! :)

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

    Your code is awesome!

  • @MihirKulkarni3
    @MihirKulkarni3 3 ปีที่แล้ว

    Great video. Thanks for sharing !

  • @user-nx6wi6eh9v
    @user-nx6wi6eh9v 2 ปีที่แล้ว

    Wow this tutorial is really good. Great job on explaining what ur doing new sub from me!

  • @Beastie-nk7on
    @Beastie-nk7on 3 ปีที่แล้ว +1

    Incredible tutorial! This was so helpful! I just have two questions. One, how can I start the algorithm from the center of the maze? Would that even work? Two, how do you add an entrance and an exit wall? Thanks again for the great tutorial!

    • @aleksandrb4635
      @aleksandrb4635 3 ปีที่แล้ว

      I didn't watch the tutorial until the end, but all you need to do is to select a node in the center as a starting node, I suppose

    • @MartinSparkes-BadDragon
      @MartinSparkes-BadDragon 2 ปีที่แล้ว +1

      @@aleksandrb4635 Exactly - you can make your maze generate from any point, and it should work just fine.

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

    how can I change the Floor and wall scale, that way its big and not small like 0.1

  • @Beastie-nk7on
    @Beastie-nk7on 3 ปีที่แล้ว +4

    This is amazing! Do you think you could show us how to make an exit?

    • @hani8261
      @hani8261 2 ปีที่แล้ว

      Hi, did you figure out how to do this?

    • @Beastie-nk7on
      @Beastie-nk7on 2 ปีที่แล้ว

      @@hani8261 Nah unfortunately not. After tinkering around with it I turned to some other projects.

    • @hani8261
      @hani8261 2 ปีที่แล้ว

      @@Beastie-nk7on awh, alright thanks :D

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

    WallState should be called CellState. Also a cell could be flagged as "Unvisitable", reflecting the notion that the cell is not a small room, but solid concrete (or whatever), allowing for another feature of the maze - i.e. places where you can't go.

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

    is there a way to change the spaces/path of the maze and is there a way to add rooms?

  • @raulherreramacias9373
    @raulherreramacias9373 2 ปีที่แล้ว

    Could you explain how to setup the free look camera and the controlls of the third person controller

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

    Can you apply this same algorithm to create a 2D maze in unity?

  • @Rohan-ep2hu
    @Rohan-ep2hu 3 ปีที่แล้ว +2

    Hey, Great Video!! But can you tell how to simulate each step of maze generation?? Like the one, you have in the clip explaining the Recursive Backtracking algorithm.

    • @ahmadsalim246
      @ahmadsalim246 19 วันที่ผ่านมา

      that will be awesome

  • @drakrtar
    @drakrtar 3 ปีที่แล้ว +1

    I follow this exactly but when I try to attach my MazeGenerator script to the object I get "The script don't inherit a native class that can manage a script". I don't get it

    • @rotmgnambiar
      @rotmgnambiar 3 ปีที่แล้ว

      You have to inherit from Monobehaviour to attach to an object.

  • @ENDERLEGEND26
    @ENDERLEGEND26 3 ปีที่แล้ว +4

    I am using ur algorithm in my fps game...

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

    Hi there!
    How can i add the player and enemys in a random way inside the maze ?
    Is that complicated?
    Best Regards

    • @ahmadsalim246
      @ahmadsalim246 19 วันที่ผ่านมา

      I also want to add

  • @Geckotr
    @Geckotr 3 ปีที่แล้ว +3

    Is this maze procedurally generated? Does the layout change everytime you hit play ?

  • @bnok5237
    @bnok5237 3 ปีที่แล้ว

    Hi , i'm new to mazes ... but i'm stuck at understanding the .Generate method used in the maze renderer 10:00 where did it come from ? what is it ? can someone explain to me ?

  • @rasvhw
    @rasvhw 2 ปีที่แล้ว

    How do I make the maze bigger? I.e. make it have more turns and twists, etc. I don't care about scaling, I just want a lot larger maze.

  • @ahmadsalim246
    @ahmadsalim246 19 วันที่ผ่านมา

    still my maze is not generated, can you help me

  • @giratina008MagicRush
    @giratina008MagicRush 3 ปีที่แล้ว +1

    Can you tell me more about the size value in MazeRenderer. I can't really use it even though its a serializedfield. I assumed it would increase the size of the walls but it doesn;t for me.

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

      th-cam.com/video/ya1HyptE5uc/w-d-xo.html -> the width/height need to be multiplied with the size as well

    • @Geckogangster1
      @Geckogangster1 3 ปีที่แล้ว

      @@_sandeepnambiar Thank you for including this, I also had the same issue.

  • @t3st3d
    @t3st3d 3 ปีที่แล้ว

    how do i increse the cell size

  • @alextheinsignificant5491
    @alextheinsignificant5491 3 ปีที่แล้ว

    This is cool but if you try to increase the size the whole generator breaks. Is there any fix to that?

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

    What is text editor u are using bro

    • @purefoxcore2848
      @purefoxcore2848 3 ปีที่แล้ว

      Same question. It's looks like vim but IDK...

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

    Are 2 walls drawn between adjacent cells? If so, won't there be z-fighting issues?

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

      Yep I think so. I should revisit this tutorial to get that fixed. Among other bugs.

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

      @@_sandeepnambiar But since the material colours are the same in both - there will be fighting going on, but no-one will notice!

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

    Is there a logical explanation on why we should delete the opposite wall? I mean, I tested without deleting it and shows a lot of "box" cells, which means the maze is not maze. But why this works?

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

      It's not really the opposite wall. A same wall exist in one cell, and in the neighbor. So, when you delete a wall for one, you need to deleted it for both. explanation : 21:10

  • @Pedroallesss
    @Pedroallesss 3 ปีที่แล้ว

    Tks a lot from Brazil

  • @LukmonAgboola
    @LukmonAgboola 2 ปีที่แล้ว

    you can scale the grid by changing the position calculations to this var position = new Vector2(-(width*size)/2+(i*size), -(height*size)/2+(j*size));
    Sandeep needs to improve his code readability for future tutorials

  • @s3198
    @s3198 3 ปีที่แล้ว

    How can we make levels? How it can be saved

  • @fifasims1996
    @fifasims1996 3 ปีที่แล้ว

    I would like to make an infinite maze, is this possible using unity?

  • @ahmadsalim246
    @ahmadsalim246 19 วันที่ผ่านมา

    it is resolved

  • @jaskierw
    @jaskierw 4 ปีที่แล้ว

    How to make this maze generator for PUN2?

  • @cptray-steam
    @cptray-steam 2 ปีที่แล้ว

    Type 'WallState' does not contain a definition for 'HasFlag'

  • @supermansbrother1678
    @supermansbrother1678 2 ปีที่แล้ว

    anyone found a good way to spawn a player or object in a open space within the maze

  • @rouxmartin2063
    @rouxmartin2063 4 ปีที่แล้ว +1

    how to change the size of the maze?

    • @tomb4006
      @tomb4006 3 ปีที่แล้ว

      i have the same question

    • @RealFakePhD
      @RealFakePhD 3 ปีที่แล้ว

      Actually I figured out a band-aid to this. It may not be a good fix depending on what your game will be. Just make a script called MazeScaler and put it on your MazeRenderer game object. adjust the Scale setting to change the size, I use a scale of 4 or 5.
      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;
      public class MazeScaler : MonoBehaviour
      {
      public int scale;
      public void Update()
      {
      transform.localScale = new Vector3(scale, scale, scale);
      }
      }

  • @lorenzzoantoniopatatt4728
    @lorenzzoantoniopatatt4728 2 ปีที่แล้ว

    very good video but I can't learn how to open the spacing between the walls

    • @hani8261
      @hani8261 2 ปีที่แล้ว

      Hi did you figure out how to do this?

  • @someonetookvolt
    @someonetookvolt 3 ปีที่แล้ว +1

    Hey, do you think you could tell us how you can make randomized exits to the maze? I would really appreciate it, I'm desperate at this point (also if someone could do endlessly generated chunks out of these, that would be amazing)

    • @hani8261
      @hani8261 2 ปีที่แล้ว

      Hi, did you figure out how to do this? I would like to do the same but haven't figured out how ;??

    • @someonetookvolt
      @someonetookvolt 2 ปีที่แล้ว

      @@hani8261 gave up after a week of trying, I hope you'll have more luck than me

    • @hani8261
      @hani8261 2 ปีที่แล้ว

      @@someonetookvolt oh no, was looking for some help😭 I completed the tutorial but found another one which seems alot easier, hopefully it goes well, thank you!!!

    • @someonetookvolt
      @someonetookvolt 2 ปีที่แล้ว

      @@hani8261 you're welcome! good luck

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

      Hello you can modify the 'Generate' method as follows:
      public static WallState[,] Generate(int width, int height){
      WallState[,] maze = new WallState[width, height];
      //Initially all the walls EXIST
      WallState initial = WallState.RIGHT | WallState.LEFT | WallState.UP |WallState.DOWN;
      for (int i=0; i< width; ++i){
      for (int j=0; j

  • @tomb4006
    @tomb4006 3 ปีที่แล้ว

    I have the problem that my maze is skew, but i want to roll with a ball through it, so the ball rolls back when i dont press a key. In the Video its the same, look at 38:32, when he walk with the player, the Z-axis change. Anyone knows help?

    • @tomb4006
      @tomb4006 3 ปีที่แล้ว

      sorry, i mean the Y-axis

  • @rojhat9148
    @rojhat9148 3 ปีที่แล้ว

    helpful video, but how can I made the corners look better?

    • @RealFakePhD
      @RealFakePhD 3 ปีที่แล้ว +1

      you have to make a script to target all the walls once they are generated, and in my case, set the x axis scale to 1.3. cleaned them right up

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

      @@RealFakePhD i know im 10 months late but if you have the time could you explain to me how to target and change the walls once they're generated?

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

      @@RealFakePhD NEVERMIND IM STUPID

    • @RealFakePhD
      @RealFakePhD 2 ปีที่แล้ว

      @@ouijajuice9496 I don't remember at this point but I do also have a script somewhere in the comment section that had the code I used to scale

  • @darkstormheute
    @darkstormheute 3 ปีที่แล้ว

    I have question, how to make inlet and outlet?

  • @reecal2960
    @reecal2960 3 ปีที่แล้ว

    When I do this Unity freezes. Is this because of the while?

    • @aleksandrb4635
      @aleksandrb4635 3 ปีที่แล้ว +1

      I'm pretty sure it is. You should be careful around whiles, maybe try to put a counter variable in your while

  • @therealzucc
    @therealzucc 4 ปีที่แล้ว

    thanks.

  • @EditSenpai417
    @EditSenpai417 2 ปีที่แล้ว

    Pov: I am here for my Backrooms

  • @Arman_Kundu
    @Arman_Kundu 2 ปีที่แล้ว

    Can you send the code for the Maze Generator Script in the chat ?

  • @liambernard6972
    @liambernard6972 2 ปีที่แล้ว

    9:55 for me later

  • @hotcocoaknight853
    @hotcocoaknight853 2 ปีที่แล้ว

    Good thing I don't need a tutorial i'm just watching so I can see all of you be bad at coding lolololololololololololololololol XD XOXOXOXOXOXOXO no jk i suck at procedural generation