PROCEDURAL TERRAIN in Unity! - Mesh Generation

Поделиться
HTML-код
  • Опубликовано: 1 фев 2025

Комментарии • 669

  • @lorenzvo5284
    @lorenzvo5284 6 лет назад +60

    I like how you don't skip steps like other tutors. You're pretty good at getting into the mindset of a beginner and figuring out possible points of confusion. Thanks for putting so much effort in.

  • @RandomTot
    @RandomTot 5 лет назад +40

    Dang now this is how you make a tutorial
    I watch it 3 times in a row
    Its entertaining

  • @vidSpac
    @vidSpac 4 года назад +248

    1:25 i ain't killing my first triangle! *puts script in a backup folder and hugs it protectively*

    • @megumilk8622
      @megumilk8622 4 года назад +19

      I feel attacked by this

    • @gbm6882
      @gbm6882 4 года назад +1

      dang relatable

    • @66farisfaris
      @66farisfaris 4 года назад +12

      Lmao that’s exactly what I did! I never used a back up folder before that but I had to my little homie and his 3 defenseless vertices!!

    • @TheGecko26
      @TheGecko26 4 года назад +8

      I just put it in the comments so it can live on in the code

    • @thedude4039
      @thedude4039 4 года назад +3

      You could've just commented it out.

  • @Algathar
    @Algathar 4 года назад +3

    I have been trying to get a hold of vertices and these triangles for some time, but I have not seen anyone teach and explain it better than you do! thank you for making my life a little easier :) it is so much easier to learn when you explain what it is we are doing, and why, rather than just "jumping into it" head on. it helps us to understand what is going on and allows us to one day become less and less dependent on step-by-step tutorials. again, thank you!

  • @bruninhohenrri
    @bruninhohenrri 4 года назад +29

    If you want to texturize your mesh, you need to generate UV's
    The simplest way to do this is to make a Vector 2 at the first variables and put this line below the vertices array setup:
    vertices[i] = new Vector3(x, 0, z);
    uv[i] = new Vector2(z / (float)zSize, x / (float)xSize);
    And in the UpdateMesh function you add:
    mesh.uv = uv;

    • @nagyFerko
      @nagyFerko 3 года назад +1

      it don't work for me. i've got the message "Object reference not set to an instance of an object"

    • @001zeal
      @001zeal 3 года назад +4

      Thank you. For anyone still struggling with this :
      add a "private Vector2[] uv;" where the variables are declared.
      in createShape, add " uv = new Vector2[(int)Mathf.Pow(vertexFieldSize + 1, 2)];"
      and within the loop for i and z, add this : uv[i] = new Vector2(z / (float)TerrainSize, x / (float)TerrainSize);

    • @jmscshipp
      @jmscshipp 2 года назад +2

      @@001zeal Thanks Yasha!

    • @andreas40588
      @andreas40588 Год назад

      @@001zeal What is vertexFieldSize?

    • @flashheart1676
      @flashheart1676 Год назад

      You need to set the uv array size:
      uv = new Vector2[(xSize + 1) * (zSize + 1)];

  • @0kr4m
    @0kr4m 2 года назад +41

    i miss brackey

  • @carduran_1154
    @carduran_1154 3 года назад +1

    It's impressive how you've been able to explain this in 13 min. Amazing

  • @CubeMasterLewis
    @CubeMasterLewis 6 лет назад +1

    I really like that you are slowing down when explaining topics. It is really helpful thanks

  • @user-py7mz8oj7o
    @user-py7mz8oj7o 4 года назад +21

    "Without further ado"
    "But 1st Skillshare ad"

  • @dc37wwe2kmods
    @dc37wwe2kmods 6 лет назад +2

    FINALLY!!! Please do more procedural tutorials!

  • @jonathanhart2888
    @jonathanhart2888 5 лет назад +4

    When adding the vert + or the tris + you can hold down alt and select all the rows to update to only type tris + or vert + one time.

  • @erikweeks8949
    @erikweeks8949 5 лет назад +10

    It definately does NOT LIKE a X and Z size of 1,000 (an extra zero was an un-intentional error on my part), on my machine lol but definately something I'll be playing about with in my spare time. Thanks for an amazingly well presented video on something that can become very complex quickly. I'll probably watch this a couple of times just to make sure it makes sense

    • @nerditstudios3457
      @nerditstudios3457 5 лет назад +2

      Did you ever figure out why? What was the bug. I am having the same issue

    • @ichoupettev4661
      @ichoupettev4661 2 года назад

      @@nerditstudios3457 same issue, did you know of to fix this ?

    • @SvantteBoy
      @SvantteBoy 2 года назад +4

      @@ichoupettev4661 "Index buffer can either be 16 bit (supports up to 65535 vertices in a mesh), or 32 bit (supports up to 4 billion vertices). Default index format is 16 bit, since that takes less memory and bandwidth."
      -> mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;

  • @luciacover9909
    @luciacover9909 6 лет назад +341

    thank you! could you make a part 2 of this video? like adding color via height and saving landscapes?

    • @mkxstudio9609
      @mkxstudio9609 6 лет назад +29

      I recommend you watch this series, if you want to know more about landmass generation ruclips.net/video/wbpMiKiSKm8/видео.html

    • @lostconflict9369
      @lostconflict9369 6 лет назад +3

      Saving landscapes sounds cool, but i guess you could just record all the values in the array and save those.

    • @RugbugRedfern
      @RugbugRedfern 6 лет назад +11

      @@lostconflict9369 Just save the noise, and generate a new mesh based on that.
      (3 years later edit): use seeds like the dude below said instead, saves a lot more space

    • @aggressivemastery
      @aggressivemastery 6 лет назад +2

      Brackeys is reposting this video, and will maybe re-post the series. He did this whole series on proc gen, so do a search for proc gen on brackeys ruclips.net/video/vFvwyu_ZKfU/видео.html is a link to the series from brackey. BTW, I love this guy.

    • @lostconflict9369
      @lostconflict9369 6 лет назад +3

      @@RugbugRedfern You wouldn't be saving the landscape then, just the noise, there's more to the landscape than just the noise.

  • @justinwr092
    @justinwr092 6 лет назад

    Best channel on RUclips. I watch you guys like every day. You guys have taught me a lot. I'm working on a game for my kids on the 4-player arcade cabinet I made for our game room. I'd be lost in the weeds without your videos.

  • @thecalcium2595
    @thecalcium2595 6 лет назад +2

    I remember programming what my lecturer called heightfields in OpenGL/Glut back a few semesters in uni. We did this in C++ and this was one of the hardest programming things we ever did because nothing were no automatic functions for stuff like normal calculations like in Unity. Going off this there was the concept of averaging normals so textures between triangles blended with each other giving off a natural or smooth transition between colours. Hardest thing ever.. never got it working though :D

  • @btarg1
    @btarg1 6 лет назад

    This is why I link to your channel whenever someone asks how to do stuff in unity. Thanks!

  • @KiwiGalaxyDev
    @KiwiGalaxyDev 6 лет назад +13

    Amazing Tutorial! Pretty well explained! I like to see a part 2 with colors and saving the landscapes. 😄

  • @happyyt266
    @happyyt266 3 года назад +39

    code:
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class MeshGenerator : MonoBehaviour
    {
    Mesh mesh;
    Vector3[] vertices;
    int[] triangles;
    public int xSize = 20;
    public int zSize = 20;
    public float strength = 0.3f;
    void Start()
    {
    mesh = new Mesh();
    GetComponent().mesh = mesh;
    CreateShape();
    UpdateMesh();
    }
    void CreateShape()
    {
    vertices = new Vector3[(xSize + 1) * (zSize + 1)];

    for (int i = 0, z = 0; z

  • @pegton1981
    @pegton1981 6 лет назад +5

    I have no idea about coding and stuff but your channel is very interesting

  • @whoisgliese
    @whoisgliese 3 года назад +1

    Brackey's videos are so relaxing and enjoyable

  • @agitated_cat
    @agitated_cat 4 года назад +4

    I love how you just say "yaay" when you are done

  • @BrainSlugs83
    @BrainSlugs83 5 лет назад +56

    Fyi, instead of incrementing "i" separately, you can increment it within the definition of the inner loop, just change "x++" to "x++, i++". Even though the value is defined in the outer loop, you can still increment it in the inner loop. 👍

    • @arcclite1144
      @arcclite1144 5 лет назад +2

      In this case, the code doesn't matter as much as the clarity. I found a lot of my refactoring of this as I did it myself was more about adding extra variables like "private var _xVertCount = xSize + 1" to increase the clarity for a future read-through (by either future me, or a hypothetical teammate/contractor). Scoping the i or incrementing inlines are nice, but they don't change the compiled code at all / irrelevant amount (and if they did, you should be using tools like ReSharper to let you know that anyway).

    • @justinc2633
      @justinc2633 5 лет назад +2

      @@arcclite1144 to 99% of people making tutorials clarity is the second priority, seems like everyone besides brackeys and a few others just speed through everything without explaining

    • @plasmarade
      @plasmarade 4 года назад

      I don't understand but ok thanks

    • @MeMe-nm7jr
      @MeMe-nm7jr 4 года назад +2

      ​ @plasmarad Bit late but I'll try to explain for you or others that see this:
      TL;DR Go to 5:50 and pause it (maybe in another window) just to see the lines of code I'm referencing. At some other point in this or first video, Brackeys was showing that you can have multiple variable assignments in the _initializer_ part of a for loop. Meaning Brackeys added the *i = 0* part to the outer loop on line 31 instead of putting that assignment above the loop, for example: *for (int i = 0, z = 0; z

    • @z08840
      @z08840 3 года назад

      i = z * zSize + x

  • @aymericplanet4329
    @aymericplanet4329 6 лет назад +1

    Seriously you are insane ! You are amazing ! I learn so much with your videos. Keep on the great job !

  • @shrodinger3844
    @shrodinger3844 2 месяца назад

    nice job! my eye kinda twitches when i see counters used the way you did with the generation of the vertices, but otherwise that's a really cool way to generate a terrain map! thank you!

  • @CouchFerretmakesGames
    @CouchFerretmakesGames 6 лет назад +109

    Pretty well explained, thanks! What will be the NEXT step in this topic?

    • @mr-matt2881
      @mr-matt2881 6 лет назад +21

      erosion algorithms plz XD

    • @rubixcube6
      @rubixcube6 6 лет назад +18

      Heres what I would like to see:
      1. How to generate terrain using an image to map its height.
      2. How to color each vertex based on its height.
      3. How to add a texture map.

    • @geri4367
      @geri4367 6 лет назад +14

      @@rubixcube6 Search "Sebastian Lague Procedural Landmass Generation", first result

    • @Zeropointill
      @Zeropointill 6 лет назад +6

      Right? I really suck at math and he's made mathematical concepts that are simple for some, yet make my brain melt when trying to learn them, actually make sense in a super simple way. This guy shouldn't be doing videos, he should be my math teacher all those years ago in school.
      (i can't stress enough how much i suck at math too. I mean my brain's like "that's it, i'm outta here" and stops working levels of sucking at it)

    • @CouchFerretmakesGames
      @CouchFerretmakesGames 6 лет назад +12

      @@Zeropointill Don't tell yourself that you suck at math. That's harmful, and you will never get out of the "I suck at math" thoughts. Give yourself time and learn it in your free time, everybody can do it, you CAN do it. It just a matter of time. :)

  • @benjoe1993
    @benjoe1993 6 лет назад

    Best explained terrain generation video out there! Good stuff!

  • @Max2000skill347
    @Max2000skill347 6 лет назад +2

    I was waiting for this tut! Thank you!

  • @ramzhamsi9762
    @ramzhamsi9762 7 месяцев назад

    after 5 years, I want to say once again, thank you

  • @epicshortstodaynow
    @epicshortstodaynow 4 года назад

    mans needs to make a masterclass right fkn now brackeys you are great

  • @grandmasterskitz748
    @grandmasterskitz748 6 лет назад

    I like how you make it seem so easy lol
    Personally, I don't watch your videos for code, but it's the content explanation that I truly get a lot out of. Even reviewing your old tutorials, no matter how basic, I always find myself learning something new.
    I'm glad to see you're sponsored and promoting! You've earned it!

  • @Saleca
    @Saleca 4 года назад +26

    i got stuck in the gizmos because they were turned off on the scene! beware of that if you dont see the gizmos.

    • @samferngamerhd4204
      @samferngamerhd4204 3 года назад +2

      Sometimes the biggest problems are caused by the simplest things. Just like when I though there was something wrong with my script because there was nothing in the console, but then I saw that the console was set to not show messages (print() or Debug.Log()).

    • @nikolakosanovic9931
      @nikolakosanovic9931 2 года назад

      I once deleted event system in scene and 2 days was trying to find reason why I can't press button

  • @TheProProgrammer
    @TheProProgrammer 6 лет назад +5

    Such a great tutorial, been waiting for this for quite a while, btw I notice you say "verticy" for the singular of vertices, actually vertex is the singular for vertices.

  • @thegamingsnorlax196
    @thegamingsnorlax196 5 лет назад +20

    Had to watch at 0.5 speed to keep up 😂

  • @ZitongWu-jr7bi
    @ZitongWu-jr7bi 2 года назад

    I really like this video. You make things easy and I like your art style.

  • @tehsimo
    @tehsimo 3 года назад

    This really demystified this process, thank you

  • @thek1llerbear570
    @thek1llerbear570 6 лет назад

    I love the perlin noise you added into the whole flat terrain thing you explained it well

  • @AmanKumar-tu2og
    @AmanKumar-tu2og 6 лет назад +1

    Another awesome video!! If you like text tutorials, you can also see catlikecoding tutorial on terrain generation, which is much similar to this

  • @m4rt_
    @m4rt_ 3 года назад +1

    4:45 another way to do it is under the vertices code put this:
    var offset = new Vector3(0f, 0.25f, 0f);
    foreach (var vertex in vertices)
    Debug.DrawLine(vertex-offset, vertex+offset, Color.red, 100f);

  • @charlotte1924
    @charlotte1924 6 лет назад +1

    7:40 Something that is neat in Visual Studio is that if you press and hold alt and drag, you can write code that repeats over those selected lines. A much quicker way of doing it line by line.
    (I appreciate doing it this way for the video. Just a hint for those who want to do this quicker :) )

  • @DualCoreStudio
    @DualCoreStudio 6 лет назад

    Didn't see this coming, thanks Brackeys :)
    - Mislav

  • @KlausiboyZ
    @KlausiboyZ 6 лет назад +9

    This is really awesome. I always imagined stuff like this was super complicated, but it looks so simple!
    On a side note, my class and I are very likely going to be studying Unity sometime within the next half year for like a month (We're a datamatician which is basically a danish work-focused computer science education) , and I'm really considering showing them some of your videos, since I feel like your videos are good for getting started with unity, and also as far as I understand you guys are danish as well.
    Any recomendations on which videos to start with? We're pretty competent with coding, been studying it for about 1½ years now (C# especially). But most of us have not been playing around with Unity

  • @Oxmond
    @Oxmond 4 года назад +1

    Looks cool! Mathf.PerlinNoise is one of my favorites! 👍🤓🧡

  • @johngrey5806
    @johngrey5806 6 лет назад

    Without further ado, I like this video!

  • @bersK00
    @bersK00 6 лет назад

    If you expose some of the params that modify the perlin noise and add OnValidate function you can make a pretty neat interactive perlin noise "generator".

    • @bersK00
      @bersK00 6 лет назад +1

      private void OnValidate()
      {
      CreateShape();
      UpdateMesh();
      }
      you add this and then
      Mathf.PerlinNoise(x * pNScale, z * pNScale) * nMultiplier you replace the hardcoded float values with public float variables and voilà.

  • @ResuelveloTu
    @ResuelveloTu Год назад +2

    Hi sir, everyting was perfect, but I have a problem. When I asign a material with a texture, no matter If I change the material x and y tilling or offset, I never see the texture details. I tryed several textures but there is no way to see the textures details. Could you help me? Thanks a lot.

    • @ResuelveloTu
      @ResuelveloTu Год назад +2

      I foud another of your videos that answered and solved my question, it is:
      MESH COLOR in Unity - Terrain Generation
      Fantastic! New sub and like 😃

  • @C_Corpze
    @C_Corpze 4 года назад

    Very useful information, I needed this a lot as I want to mess around with Voxels in Unity and world generation.

  • @obalfaqih
    @obalfaqih 6 лет назад

    Thanks! Always creating interesting tutorials 👌🏻👌🏻

  • @HAWXLEADER
    @HAWXLEADER 6 лет назад

    BRACKEYS Start using visual Studio code it will save you so much time!
    Faster loading, multi line editing(alt) , moving lines(alt+arrows) , selecting text and encapsulating it in brackets, ctrl+/ for commenting, quick refactoring, easy better text completion (ut tab for. Update gtn for get component) and so much more.

  • @ae112r
    @ae112r 6 лет назад +1

    This is exactly what I needed, thank you!

  • @TimbavatiLion
    @TimbavatiLion 6 лет назад +7

    And now to add a Collider that actually fits the mesh :P

    • @iustall
      @iustall 6 лет назад +9

      Add a mesh collider to your object and add this line inside void Start(), after updateMesh();
      GetComponent().sharedMesh = mesh;

    • @TimbavatiLion
      @TimbavatiLion 6 лет назад +1

      @@iustall huh, that easy :D Thanks!

    • @gavinriddick401
      @gavinriddick401 19 дней назад

      Lifesaver

  • @TheMastercheeff
    @TheMastercheeff 6 лет назад

    A nice and easy to follow video, I'd been thinking how is this possible for some time now.

  • @bmatt96
    @bmatt96 6 лет назад +1

    Great video. I wanted to learn procedural mesh generation... Ended up making game that procedurally creates terrain based on an image.

  • @samuql5384
    @samuql5384 3 года назад

    5:55 you can also define the Array just like this: triangles = new int[3] { 0, xSize + 1, 1 };

  • @davidzap
    @davidzap 6 лет назад +31

    Don't forget to add a mesh collider

    • @lorenzvo5284
      @lorenzvo5284 6 лет назад +9

      or do and be frustrated ;_;

    • @vinnyorlando4930
      @vinnyorlando4930 6 лет назад

      I tired. It doesn’t seem to work.

    • @davidzap
      @davidzap 6 лет назад +3

      try with the "is convex" checkbox

    • @vinnyorlando4930
      @vinnyorlando4930 6 лет назад

      @@davidzap yea.. i figured that out.. i had gotten confused and thiught that was force rigidbodys only

    • @raik1766
      @raik1766 3 года назад

      or you make a own colliding system and stop lagg spikes of occouring on a huge mesh

  • @adempenver9416
    @adempenver9416 6 лет назад

    nice trick with putting the i in the for loop! Never thought about doing it like that...

  • @paulamicel
    @paulamicel 3 года назад

    I am at 0:57 and I already clicked 👍just for that wonderful smile

  • @craftingnerf2593
    @craftingnerf2593 3 года назад +3

    This code works great even with the latest LTS version of Unity (20.04 I think)
    although one problem I found with it
    if you go past 255 the mesh does the triangle across the layer (I dont know how to explain it but its the problem that was solved with the vert++)

    • @jaxon_hill
      @jaxon_hill 3 года назад

      did u find a fix?

    • @alainray
      @alainray 2 года назад +1

      @@jaxon_hill Hi, I was having the same problem. It seems Unity has a vertex limit of 256x256 per mesh. So if you want to have something greater than that, you need to add an extra mesh.

    • @alexspencer8997
      @alexspencer8997 2 года назад

      @@alainray I wish I had seen this comment so much sooner than I did, would have saved me so much time!

  • @Hello-sq3eh
    @Hello-sq3eh 4 года назад

    Unity was saying Vector 3 [] does not contain a value for 'length' and no accessible extension method....
    I tried to figure out what went wrong for about an hour and re-watched the video like 5 times and eventually figured out I didn't capitalize the L in length. Grr. Great tutorial though!

  • @coolboidoesstuff9828
    @coolboidoesstuff9828 5 лет назад +4

    Brackeys: Without further ado, let's get started!
    Also Brackeys: But first, this video is sponsored by...

  • @zacharykinsella4871
    @zacharykinsella4871 4 года назад +5

    I can't believe I just learned you can have multiple local variables in a for loop

  • @wk1247
    @wk1247 5 лет назад

    this creates each quad to be square, his would offset if you try and apply vertex color to the next vertices:
    triangles[tris + 0] = vert + 0;
    triangles[tris + 1] = vert + xSize + 2;
    triangles[tris + 2] = vert + 1;
    triangles[tris + 3] = vert + 0;
    triangles[tris + 4] = vert + xSize + 1;
    triangles[tris + 5] = vert + xSize + 2;

  • @someone4422
    @someone4422 6 лет назад

    You uploaded the video while I was sleeping there was 3;00 AM

  • @FolNico
    @FolNico 6 лет назад

    Cool vid bro! Love your content!

  • @rejwan100
    @rejwan100 6 лет назад +2

    Love your videos, great content as always!
    Just one note that bothered me, placing variables declaration inside the for loop is bad practice IMHO - Readability is more important than the "less code" in this case

  • @subramanyam2699
    @subramanyam2699 6 лет назад

    You are a great teacher breackies.. You can make learning awesome. Tnq very much :)

  • @AtheistPhoenix
    @AtheistPhoenix 4 года назад +2

    watching this I just had a flashback to doing 2D FEA analysis when he got to triangles

  • @Nexus-rt1bm
    @Nexus-rt1bm 4 года назад

    Nice tutorial, Helped me with mine in three.js

  • @jens2481
    @jens2481 6 лет назад +1

    oh my god, just wow! I used to program in UE4 Blueprints due to me being too lazy to attempt actual code.. I think I'm going to test out Unity for now as i try to learn genuine text code!

    • @gabegonzalez2782
      @gabegonzalez2782 4 года назад

      Hey how did you do this in ue4 blueprints?

    • @jens2481
      @jens2481 4 года назад

      @@gabegonzalez2782 That's the thing, coding anything procedural in UE4 Blueprint is something i never figured out. It might not even be possible. That was why i moved over to Unity

    • @gabegonzalez2782
      @gabegonzalez2782 4 года назад

      @@jens2481 ah ok well thanks.

  • @CoReeYe
    @CoReeYe 6 лет назад

    Very interesting topic. Good job the Danish king!!

  • @sytix1
    @sytix1 6 лет назад

    Very good video

  • @ThefamousMrcroissant
    @ThefamousMrcroissant 6 лет назад

    You don't need "i", you can express the index through z*(xSize+1) + x at 4:00

    • @jld9444
      @jld9444 5 лет назад +1

      i is more readable. I'd prefer to walk into Brackeys' code rather than the option of z*(xSize+1) + x

  • @SnowTerebi
    @SnowTerebi 6 лет назад

    Awesome tutorial as usual! Do you plan to make another mesh tutorial about how to do a real-time dynamic mesh? For example maybe simulate a bouncy or jelly ball that can change shape according to physics simulation?

  • @RaidHelper
    @RaidHelper 5 лет назад +2

    Hey Brackeys, I'm a huge fan of your vids since the first video, and thanks to you I just got the courage to make my own game. I'm now a beginner game developer :) and I don't know the differences between procedural terrain and the terrain we made using tools in unity and other tools like blender etc. Can you guide to which one to use according to game structure? Thanks A lot!

  • @filipgawlik3259
    @filipgawlik3259 5 лет назад

    @Brackeys,
    You again save my life :)

  • @Alex-ir3wr
    @Alex-ir3wr 4 года назад +2

    RIP BRACKEYS

    • @rotinoM0
      @rotinoM0 4 года назад

      Brackeys is not dead

    • @Alex-ir3wr
      @Alex-ir3wr 4 года назад +1

      @@rotinoM0 no u dont understand. The brackeys RUclips channel is dead

    • @redstoneninja3375
      @redstoneninja3375 4 года назад +1

      @@rotinoM0 the channel is dead 😭

  • @nielsostman
    @nielsostman 6 лет назад

    So, without further ado let's generate some terrain. But first this video is sponsored... 🤔
    Thank you for the great content!

  • @simoncodrington
    @simoncodrington 6 лет назад

    Thanks for the new video mate :)

  • @forestlapointe1448
    @forestlapointe1448 3 года назад

    I had a diagonal line of squares that wouldn't generate
    in case anyone else comes across this issue, in your "for" loops dealing with the triangles, make sure you're using "x < xSize" and not "x

    • @raik1766
      @raik1766 3 года назад

      thats just going to make your quad miss 1 line

  • @ReinkeDK
    @ReinkeDK 6 лет назад +6

    Could you make a version where you use the new ECS system instead?
    I know it's not needed for this, but to follow the flow :)

  • @MrOchmelka
    @MrOchmelka 5 лет назад +6

    hello, could you make a tutorial about marching cubes terrain? I would like to edit terrain like digging in game. Thank you.

  • @InFlamesOfSorrow
    @InFlamesOfSorrow 6 лет назад +49

    Could you please make a Tutorial on Generating a 2d Terrain, like in the game Terraria?

    • @Ronitrocket
      @Ronitrocket 5 лет назад +1

      well, with something like that, all you would need to do is rotate it 90 degrees, and morph the top

    • @Ronitrocket
      @Ronitrocket 5 лет назад +6

      however, it would not be the greatest idea to use a mesh for that depending on world size. 2d games suffice fine with sprites

    • @skyacaniadev2229
      @skyacaniadev2229 5 лет назад +2

      Terraria is a side scroll, you are basically generating platform and walls... Also, they have a very cool fliud system, that might require some serious coding skills..

    • @magnusm4
      @magnusm4 5 лет назад +1

      To get a little better look at how Terraria works and optimizes the whole world just watch the video:
      How does Terraria handle thousands of tiles? | Bitwise
      It's rather funny as it handles a bunch of sprites in a box that it turns on and off and has these in a large group together instead of checking every single sprite.
      Instead it checks a distance and enables a whole group at once, saves a lot of processing.

    • @pureay2700
      @pureay2700 4 года назад

      Marching squares. Is what you want

  • @MintySenpai
    @MintySenpai 4 года назад +1

    WOW.. Just wow. Thanks you so much!

  • @nielsvdmarel
    @nielsvdmarel 6 лет назад

    Amazing video! could you also explain more about the algorithm needed to generate a Ico Sphere and how to adress a certain amount of generated triangles (like adding a certain collider to a certain amount of connected generated vertices).

  • @dayellowdart1239
    @dayellowdart1239 5 лет назад +1

    Always amazing videos! Cannot tell you how helpful all of these have been. If you by chance see this, can you go through the differences between procedural generation of a MESH verses a TERRAIN. I have completed a code to generate a MESH from a .XML consisting of points and triangles...and even though the points and triangles are well defined and crisp originally, the Mesh builds kind of bubbly and approximate. How can I fix this? Should I build a Terrain instead of a Mesh to gain more definition? Would be happy to discuss. Thank you!

  • @icec00l3d5
    @icec00l3d5 5 лет назад +8

    Could you do a tutorial on a procedural hexagonal terrain?
    Context:
    I'm trying to make a game like Minecraft but with Hexagonal Prisms instead of blocks

    • @edgunther8136
      @edgunther8136 5 лет назад +3

      Hexagon math is hard. I wish you luck!!
      If you're trying to start small, do this exact video but with a 2D hexagon grid. The verts will deal with square root math and each mesh will be 4 triangles instead of two.

    • @icec00l3d5
      @icec00l3d5 5 лет назад +1

      I've managed to generate a hex grid (Only the vertices triangles are next) but I can't get it to square up, right now it forms a rhombus and it's not the most convenient to work with.

    • @edgunther8136
      @edgunther8136 5 лет назад +1

      @@icec00l3d5 getting what to square up? What's in the shape of a rhombus?

    • @icec00l3d5
      @icec00l3d5 5 лет назад

      @@edgunther8136 Sorry I was vague but I managed to fix it, ty

  • @Flowerpot2905
    @Flowerpot2905 2 года назад

    Brilliant! Thanks for the video.

  • @bagellpower2311
    @bagellpower2311 6 лет назад

    YES exaclt what i was looking for cheers

  • @ArnoldsKtm
    @ArnoldsKtm 5 лет назад +5

    Put these in a playlist or link them by a tag! It's a mess to find them together.

  • @LeNumberJ
    @LeNumberJ 6 лет назад

    nice woodwood hoodie!

  • @gregoryfenn1462
    @gregoryfenn1462 6 лет назад

    “No you are not the zSize, you are the zSi-eezze: double the e, double the zee, double the flavour”. (A joke only British people who watched the film adaption of “Rock of Ages” will get.)

  • @zok_6619
    @zok_6619 4 года назад +3

    I have the error Index out of range exemption. What do I have to do? It won’t load the z koordinates

  • @the_blocktopus
    @the_blocktopus 3 года назад

    thank you so much, i tried this on my own yesterday and got utterly defeated by the triangles that connect from 1 row to the other (The ones that draw on the backside like at 10:42)
    didnt think of putting the triangle creator into 2 for loop like a grid.

  • @rolo1632
    @rolo1632 3 года назад

    For those who need / want to add colliders and can't use franku kek code for some reason do this:
    Go to the top under public int zSize and add this:
    private MeshCollider meshCollider;
    Then go to the update mesh function and add this:
    meshCollider.sharedMesh = mesh;
    Enjoy 😉

    • @raik1766
      @raik1766 3 года назад

      Note that this will affect your performance if the mesh is large

  • @sammyhamdan9534
    @sammyhamdan9534 5 лет назад +1

    In case anyone else is having the issue with the Gizmo's not showing:
    Unity won't draw them if you have the script collapsed in the inspector.

  • @bdgaminggr1697
    @bdgaminggr1697 4 года назад +6

    TIP: If you are creating a massive terrain (big xSize and zSize) do mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; UNDER GetComponent().mesh = mesh;

  • @michaelarcholekas6782
    @michaelarcholekas6782 2 года назад +1

    For some reason this works fine up to 200x200 but when i try 1000x1000 it creates only half of the rectangles

  • @reedrendered
    @reedrendered 5 лет назад +2

    works great, however I was wondering how to make the new mesh collide with things, as I cant seem to get a player not to just fall straight through.

    • @PraYogiz
      @PraYogiz 5 лет назад

      I'm new in unity, I try add this line in void update function = GetComponent().sharedMesh = mesh;
      also, you need to add meshcollider component in mesh generator node inside editor. Its work for me, but I don't know is it the proper way or not :D

    • @reedrendered
      @reedrendered 5 лет назад

      @@PraYogiz that would make sense ill give it a try

  • @anichebhargav
    @anichebhargav 6 лет назад

    Thanks for this! Could you please make a video on how to chart graphs in Unity to simulate data? For stock market games and stuff.

    • @CouchFerretmakesGames
      @CouchFerretmakesGames 6 лет назад

      Hey, Code Monkey has a similar video on this: ruclips.net/video/YI-18iApelA/видео.html

  • @somekid1877
    @somekid1877 3 года назад +1

    Very good tutorial! There's one part I'm hung up on though. How come Brackeys uses shared vertices in his algorithm? I thought using shared vertices makes the lighting go all wacky or what not, since the normals cannot be calculated properly? I've actually recreated the algorithm using non-shared vertices but I'm just not sure if its worth it to write my code this way?

  • @SaSeshen
    @SaSeshen 4 года назад

    Right, so, basically.... *Mind Blown*.
    Seriously though... how would you go about attaching textures, or objects on top of this terrain that was computationally generated? I think on a Sky view of the problem, you would simply add lines of code that discuss Instantiation, calling objects, and potentially randomizing their placement, with potential algorithmic alternatives to account for clumping and shaping, but is that actually right? What would code like that even begin to look like?
    I'm asking this question and in full disclosure I have no desire to even try this yet because I am significantly out of my depth with this complexity lol. That being said, if I did want to create a world map this is EXACTLY how I would go about doing it and all I would want to do is a have a library or textures, and objects that get called by the algorithm and generate as needed.
    I watched a video of rendering the Mandelbrot fractal and the thought had occurred to me to make a world map that can iterate through the Mandelbrot fractal as an interactive player space. However, I am almost absolutely certain, that gets into a complexity of math that may very well be beyond the scope of Unity?