Tile Map auto generation in Unity - TUTORIAL

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

КОМЕНТАРІ • 108

  • @DHofmann
    @DHofmann  4 роки тому +74

    It makes me very happy, that this video still gets a lot of views after nearly 3 years :-D
    I would love to answer your questions here, cause you are all very kind.
    But I must admit that I turned my back on Unity in 2018 to continue with Godot and gdscript.
    Since then I have forgotten nearly everything on programming in c# or even starting a project in Unity.
    So I hope you understand if I can't support more detailed questions on this video any longer :(

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

      Thank you for the great tutorial!

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

      Daniel Hofmann would you be able to add tress and stuff onto this code or would that all be separate?

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

      Yes, @@electroman9254 , I think this is a good idea to add this to the code.
      I remember experimentating a little bit in this direction with code. But this was a looong time ago and I can't remember, because I am old now :))

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

      Daniel Hofmann ah ok thx

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

      Maybe make a tutorial on how to do it on godot?

  • @BITOverflow
    @BITOverflow 5 років тому +7

    If you are using an older version of the rule tile addon, make sure to use the RuleTile class instead of TerrainTile. I had problems figuring out why this won't work, hope this info will help somebody in the future. Great job Daniel, the grid and tile manipulation part helped me a lot!

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

    This was a fantastic tutorial. First time I followed along I had no idea what you were talking about but after reading about cellular automata and watching your video again it made total sense. Thank you!

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

    Great tutorial, worked flawlessly. Thanks so much for this, really helped me understand how to implement an procgen system using an established algorithm. Please keep doing this, it is definitely appreciated!

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

    AMAZING!!! I have been hunting for this type of tutorial, you have done a great job and I was able to adapt to my code easily. Thank you so much!

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

      Thanks a lot. I am glad it helped you. Your words are a great motivation to me.

  • @Oscar-lp6zd
    @Oscar-lp6zd 2 роки тому

    Really helpful video that has given me a lot of motivation - going to build off of your basic generation and see if I can get some logic going for my own tilemaps to create an environment for the player to explore. Thank you so much!

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

    Truly amazing. Thank you for such a helpful guide and for providing your materials and project files to help tie up loose ends that may have not made sense in the video. You, Brackeys, and a few others have really helped me to create my own game. Cheers.

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

    Hey man, I think your tutorial is quite enlightening. Thanks.

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

    AWESOME, thanks. This code is also pretty performance, I updated my procedural generator with this for a platformer. Thanks!

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

      Thanks a lot. I am glad that the code helped you with your project!

  • @naroxo3067
    @naroxo3067 5 років тому +2

    this is pure gold to me, tank you

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

    That was super helpful, thanks for putting that together. Keep up the good work.

  • @aidenkimmerling7221
    @aidenkimmerling7221 3 роки тому +2

    Hey I know this is an old video, but how do I change where the procedural generation starts. Say I wanted it to start at 100, 100 instead of 0,0. How would I go about doing that?
    EDIT: I found out how. For any of you wondering, I accomplished this by adding a new Vector3Int called startPosition, and adding it at the beginning of this: topMap.SetTile(new Vector3Int(startPosition.x + -x + width / 2,startPosition.y + -y + height / 2, 0), topTile);
    botMap.SetTile(new Vector3Int(startPosition.x + -x + width / 2,startPosition.y + -y + height / 2, 0), botTile);

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

    hello i using unity 2020 i have a problem i dont see under assets>Create Tile how create i them?

  • @iitsmeromii
    @iitsmeromii 2 роки тому +1

    Wait those arent crabs dying

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

    Amazing thank you for sharing this!

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

    very goood film, thank you

  • @SKiDDiBusy
    @SKiDDiBusy 5 років тому +3

    How would this be implemented into a world you're trying to create in which there are multiple terrain resources that you also want to include on the map I.E. factorio where there are multiple types of resource nodes also procedurally generated on the map?

  • @WCIIINoob
    @WCIIINoob 5 років тому +4

    wow, thanks! I saved a lot of time with your tutorial and it's the perfect introduction to unity for me :D
    Your last video was about godot - did you stop working with unity?
    Also a litte question to your code:
    I can't interpret the line "terrainMap[x, y] = Random.Range(1, 101) < iniChance ? 1 : 0;"
    TerrainMap[x,y] will be filled with a random value, range 1-101. But the < iniChance ? 1:0 is not readable/interpretable for me :-S Could you give me a hint?

    • @Mauwh
      @Mauwh 5 років тому +4

      The question mark and colon is a ternary operator, which is basically a short if/else statement. If Random.Range(1, 101) < iniChance, return 1, else return 0.

    • @WCIIINoob
      @WCIIINoob 5 років тому +2

      @@Mauwh Thanks a lot! I didn't know this short if/else statement, you helped me a lot, Thank you!

  • @_.-.
    @_.-. 4 роки тому

    What I don't get is how can the code tell which tile to use so everything correctly lines up graphics wise

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

    IndexOutOfRangeException: Index was outside the bounds of the array.
    mapGeneration.genTilePos (System.Int32[,] oldMap) (at Assets/Scripts/mapGeneration.cs:90)
    mapGeneration.doSim (System.Int32 numR) (at Assets/Scripts/mapGeneration.cs:51)
    mapGeneration.Update () (at Assets/Scripts/mapGeneration.cs:128)

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

    I was just wondering, how does one make a procedural chunked tile map, with rule tiles, without the seams?

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

      Have you figured it out? Cuz I’m in the same boat. Was going to do sub scenes, come to find out they don’t work with tile maps, and idk what to do lol

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

    Thank you very much for this tutorial. Everything is working perfectly. I just have one question: You said if you want to remove borders then comment out something, could you please tell me which line of code should I comment out?

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

      Thanks a lot. It is the line at 16:15 which should be commented out, if you want no border. neighb++

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

    Could you perhaps create a new tutorial to explain how to make a scriptable tile in unity?

  • @aryssero7104
    @aryssero7104 3 роки тому +1

    13:52
    this is a completely random time stamp

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

    it says i can't add the script because it needs to derive from mono behavior

  • @TheBallzackz
    @TheBallzackz 7 років тому +3

    excellent programming, but the directions need to be a bit more synced with what you are doing. I only have 1 screen so if I am going to follow along with you I need to stop looking at what you are typing and when i come back you are typing something very different. makes it hard to follow at times.

    • @DHofmann
      @DHofmann  7 років тому +5

      Thank you. I really appreciate your constructive feedback.
      Actually this was my very first scripting tutorial and I know I quite
      have to improve on this.
      I will review the video and try to figure out how to get better at this.

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

    How can i do a auto border as you did in the beggining of the video? trying to make this on my rpg to faster level design

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

    Very good tutorial

  • @aygian1671
    @aygian1671 3 роки тому +1

    Hey man!
    I absolutely love your tutorial, I have one question however.
    How would I go about laying out an array of tiles? Lets say I want to set 25% of 1 tile and 75% of another on the bottom layer?
    If anyone could help me with this I'd be very greatful.

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

    When i do this, the bottom tiles dont show

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

      Turns out the bottom tilemap is in the same postion as top tilemap.

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

      @@vortexplays4946 I have the same problem.

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

      @@adamex2270 Adamex in the dosim() theres an if statement that shouldnt be followed by curly brackets {} and should just have the next two line of codes that set the topMap n BotMap .settiles . If you have the {} then get rid of them

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

      @@vortexplays4946 Thanks, it worked.

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

      thank you!

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

    I followed along exactly and even used your script after mine didn't work and it doesn't work. I put in 'Debug.Log("Click")' inside of 'if (Input.GetMouseButton(0))' to push a line to console after using the mouse button. The line shows up, the map does not. Any help?

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

      It was a unity bug. I had to start a new project and import all of the assets again, then it worked.

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

    This could also be used to make more natural textures for pixel art.

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

    everything was going well until i tried to assign the toptile tile asset in the inspector and it just wont let me

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

      It's because of depreciated scriptable objet instanciation. You cannot use new Object anymore but must cast it as type :0 LavaTile myAT = ScriptableObject.CreateInstance("LavaTile") as LavaTile

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

    So this is working as intended for me though I had to make a few changes to get it to work with my version of Unity. The question I have here is how this is working as it is. The portion of doSim that creates the top and bottom tilemap is what confuses me. I get that it's creating the top tile whenever there's a 1 as it iterates through the array. What I don't get is how it's using that same logic for the bottom tile since it's filling both of them. When I go look at the bottom tilemap it looks like it just fills the whole tilemap with the bottom tile. I mean it works and looks as I expect it to but I don't understand how it's logically doing that.

    • @darkmojojojo
      @darkmojojojo 2 роки тому +1

      Okay, just saw what it is. I copied his tab indenting for the if statement. The second SetTile method runs no matter what the result of the if statement is so that's how it's filling it and is not part of the if statement at all.

    • @blight79poop61
      @blight79poop61 11 місяців тому

      @@darkmojojojo I was having the same problem, thanks for finding that.

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

    Hi Daniel great tutorial. I was just wondering if you could explain the 'Birth Limit' and 'Death Limit' variables, as I'm not totally sure what they are doing.

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

      So I know this is an old question but best as I understand it, the foreach before that variable is checked counts the number of neighbors within the 8 tiles around the current tile it's iterating through. It then compares the deathLimit and the birthLimit to the number of neighbors to determine whether the tile dies or if a new tile is born. If neighbors is less than the death limit, the tile "dies" (is set to 0). If neighbors is greater than the birth limit, a tile is "born" (is set to 1). If neither condition is met, nothing happens and the for x and y loops continue.

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

    23:50
    how did you create a texture box ???
    please help me!!!
    I can not do this

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

      Hi @GGMemes,
      Very simple in Unity under Menu Assets -> Create -> Sprites -> Square. Then set the pixels per unit and a color of your choice.
      I do not know if this was possible already when I did this tutorial.
      So I created this rather complicated in a graphics program, by creating a new document 24x24 and exporting it as a png-file.

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

    Hey there, any chance you can give a thorough explanation of how the "BoundsInt" works in general and in the context of this program? Cannot find good information about it on the internet. :/

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

      Hi, I am sorry, but I turned my back on Unity and switched to Godot. So I won't do any more Unity tutorials.
      But in my Godot-Tutorial on the same topic I reproduce the BoundsInt Array with c#-Code, because Godot has no Bounds-Int:
      ua-cam.com/video/OKBVk1I4Ddk/v-deo.html
      I also made a visual explanation for this using some animated cells:
      ua-cam.com/video/0lWIAu8OO-A/v-deo.html
      So hopefully, if you watch this videos, it will give you a better understanding of how the Bounds-Int works. It's really good for Tilemaps, but also simple to reproduce with your own code.

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

      @@DHofmann Thank you! That gave the push we needed to understand how it works!
      Keep up the good work!

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

    I've done all of the coding, but when i add my script to my empty game object i dont get any of the sliders showing, how do i fix that?

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

    hi it's very great tutorial really helped me i just have on question can i randomize the top tile like adding more than one tile and randomize it , i tried playing with the code a little bit but i cant find a method to do so can you help me with that
    and thanks in advance :)

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

      @@prettybigoof3135 hi im new to unity and C#, where should put the code

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

    thank you so much!

  • @香梨-n7c
    @香梨-n7c 4 роки тому

    里面代码有一段是错误的,导致重叠,生成瓦片时要改一改才行,

  • @weteamsteve1280
    @weteamsteve1280 7 років тому +1

    Awesome!

  • @torr.y
    @torr.y 7 років тому +1

    Oh thank you man

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

    Thanks

  • @PK-se2jh
    @PK-se2jh 2 роки тому

    thankyou :)

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

    Is he in some kind of VIM mode ?

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

      Yes I am. Always used Vim at work, therefore I am much quicker with it . The extension for VS can be downloaded here: marketplace.visualstudio.com/items?itemName=JaredParMSFT.VsVim

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

      @@DHofmann
      23:50
      how did you create a texture box ???
      please help me!!!
      I can not do this

  • @PedroHenrique-rl9dj
    @PedroHenrique-rl9dj 2 роки тому

    Great tutorial but i gotta say your spaces and wrong indentation drives me crazy LOL

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

    Where is git?

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

    Hey, good tutorial but for some reason the auto gen is very messy.. can someone help me pls
    nvm XDD

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

    A+

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

    Might just be my shitty headphones but I can barely hear this

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

    thx

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

    Ich kann dir leider nich genau sagen, wiesos mir so schwer fällt, deinen Erklärungen zu folgen aber Sebastian Lauges Tutorial über Maperstellung mit Zellulären Automaten war für mich viel einfacher zu verstehen... (ua-cam.com/video/v7yyZZjF1z4/v-deo.html)
    ich glaub ich war von deinen Methoden- und Variablennamen teilweise verwirrt und habe auch überhaupt nicht verstanden, was der boolsche Parameter "complete" in der Methode "clearMap" zu suchen hat.
    Und im Allgemeine finde ich dieses Tutorial auch schlecht strukturiert: Du machtest mir nicht eindeutig genug klar, wann du welchen Teil des Algorithmus geschrieben hast und was welcher Teil deines Codes überhaupt macht. Ebenfalls fand ich es eine vertane Möglichkeit, dass du keine Zwischenstände präsentiert hast.
    So viel zu meinem Feedback über dieses fast drei Jahre altes Video, nimms mir bitte nicht persönlich ok :)

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

      Ich schätze es sehr, dass Du Dir die Zeit genommen hast so eine ausführliche Kritik für mich zu hinterlassen.
      Und ich denke Du wirst mit dem meisten recht haben.
      Ich glaube ich habe damals sogar versucht Sebastian Lagues Stil zu kopieren. Ich war ein schlechter Dieb ;-).
      Leider kann ich nicht zurückgehen und meinem Vergangenheits-Ich sagen: "What have you DONE?".
      Andererseits: auch wenn ich heute vor Scham im Boden versinken würde, falls ich mir das Video erneut anschauen sollte, bin ich immer noch sehr froh, dass es nach so langer Zeit gut views generiert und mir ging es vor allem darum, zu zeigen, was mit dem damals neuen Tile-Editor von Unity möglich war.

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

      ​@@DHofmann Jepp, das ist ja auch die Hauptsache :) Ohne dich hätt ich gar nicht erfahren, dass man Tilemaps auch per Skript generieren kann, hab also meinen besten Dank [^^]

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

    what

  • @RetroGamingClashOfClans
    @RetroGamingClashOfClans 5 років тому +2

    lacks explanation

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

    Woow! Even more unreadable code!.... Please use sane variable names and correct conventions...
    PS: I’m not saying this in a mean way…

    • @DHofmann
      @DHofmann  2 роки тому +1

      Thx for the feedback and advice. Sorry, but I even do not remember how to code one line in unity or c# after 4 years.

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

    Terrible naming conventions. "myB"? Seriously?