PROCEDURAL TERRAIN in Unity! - Mesh Generation

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

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

  • @vidSpac
    @vidSpac 4 ปีที่แล้ว +244

    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 3 ปีที่แล้ว +8

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

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

      You could've just commented it out.

  • @lorenzvo5284
    @lorenzvo5284 5 ปีที่แล้ว +54

    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.

  • @0kr4m
    @0kr4m ปีที่แล้ว +37

    i miss brackey

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

    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)];

  • @RandomTot
    @RandomTot 5 ปีที่แล้ว +40

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

  • @luciacover9909
    @luciacover9909 5 ปีที่แล้ว +341

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

    • @mkxstudio9609
      @mkxstudio9609 5 ปีที่แล้ว +29

      I recommend you watch this series, if you want to know more about landmass generation th-cam.com/video/wbpMiKiSKm8/w-d-xo.html

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

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

    • @RugbugRedfern
      @RugbugRedfern 5 ปีที่แล้ว +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 5 ปีที่แล้ว +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 th-cam.com/video/vFvwyu_ZKfU/w-d-xo.html is a link to the series from brackey. BTW, I love this guy.

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

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

  • @user-py7mz8oj7o
    @user-py7mz8oj7o 3 ปีที่แล้ว +21

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

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

    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

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

      Thanks I didn't know where i messed up but now i know!

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

      It isn't working like for proper generation, it exists but as a flat plane

  • @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 ปีที่แล้ว +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;

  • @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!

  • @jonathanhart2888
    @jonathanhart2888 4 ปีที่แล้ว +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.

  • @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 4 ปีที่แล้ว +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 4 ปีที่แล้ว +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 3 ปีที่แล้ว +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

  • @thegamingsnorlax196
    @thegamingsnorlax196 4 ปีที่แล้ว +20

    Had to watch at 0.5 speed to keep up 😂

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

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

  • @Freakhealer
    @Freakhealer 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

  • @thecalcium2595
    @thecalcium2595 5 ปีที่แล้ว +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

  • @ramzhamsi9762
    @ramzhamsi9762 2 หลายเดือนก่อน

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

  • @CouchFerretmakesGames
    @CouchFerretmakesGames 5 ปีที่แล้ว +109

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

    • @mr-matt2881
      @mr-matt2881 5 ปีที่แล้ว +21

      erosion algorithms plz XD

    • @rubixcube6
      @rubixcube6 5 ปีที่แล้ว +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 5 ปีที่แล้ว +14

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

    • @Zeropointill
      @Zeropointill 5 ปีที่แล้ว +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 5 ปีที่แล้ว +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. :)

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

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

  • @CubeMasterLewis
    @CubeMasterLewis 5 ปีที่แล้ว +1

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

  • @pegton1981
    @pegton1981 5 ปีที่แล้ว +5

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

  • @KiwiGalaxyDev
    @KiwiGalaxyDev 5 ปีที่แล้ว +13

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

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

    IF YOU'RE TRYING TO UPSCALE PAST 256^2, Unity don't like that many verts by default so it makes your mesh all screwy. TO FIX: Right below the line
    mesh = new Mesh();
    Add the line:
    mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;
    This takes your max verts from ~65,000 to about 4 billion (apparently).

    • @fatiherolmuhendislik
      @fatiherolmuhendislik 9 หลายเดือนก่อน +1

      OH MAN YOU ARE LIFE SAVER THANKS A LOT !!!!!

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

    Brackey's videos are so relaxing and enjoyable

  • @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);

  • @craftingnerf2593
    @craftingnerf2593 2 ปีที่แล้ว +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 2 ปีที่แล้ว

      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!

  • @zacharykinsella4871
    @zacharykinsella4871 4 ปีที่แล้ว +5

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

  • @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 😃

  • @btarg1
    @btarg1 5 ปีที่แล้ว

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

  • @MrOchmelka
    @MrOchmelka 4 ปีที่แล้ว +6

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

  • @justinwr092
    @justinwr092 5 ปีที่แล้ว

    Best channel on TH-cam. 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.

  • @TimbavatiLion
    @TimbavatiLion 5 ปีที่แล้ว +7

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

    • @iustall
      @iustall 5 ปีที่แล้ว +9

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

    • @TimbavatiLion
      @TimbavatiLion 5 ปีที่แล้ว +1

      @@iustall huh, that easy :D Thanks!

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

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

  • @MrSuperTeenGohan
    @MrSuperTeenGohan 5 ปีที่แล้ว +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

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

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

  • @TheProProgrammer
    @TheProProgrammer 5 ปีที่แล้ว +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.

  • @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;

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

    FINALLY!!! Please do more procedural tutorials!

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

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

  • @adempenver9416
    @adempenver9416 5 ปีที่แล้ว

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

  • @bersK00
    @bersK00 5 ปีที่แล้ว

    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 5 ปีที่แล้ว +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à.

  • @HAWXLEADER
    @HAWXLEADER 5 ปีที่แล้ว

    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.

  • @bmatt96
    @bmatt96 5 ปีที่แล้ว +1

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

  • @aymericplanet4329
    @aymericplanet4329 5 ปีที่แล้ว +1

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

  • @InFlamesOfSorrow
    @InFlamesOfSorrow 5 ปีที่แล้ว +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 4 ปีที่แล้ว +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 4 ปีที่แล้ว +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 3 ปีที่แล้ว

      Marching squares. Is what you want

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

    I was waiting for this tut! Thank you!

  • @ReinkeDK
    @ReinkeDK 5 ปีที่แล้ว +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 :)

  • @AmanKumar-tu2og
    @AmanKumar-tu2og 5 ปีที่แล้ว +1

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

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

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

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

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

  • @rejwan100
    @rejwan100 5 ปีที่แล้ว +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

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

    10:53 glass break?

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

    This really demystified this process, thank you

  • @ArnoldsKtm
    @ArnoldsKtm 5 ปีที่แล้ว +5

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

  • @TheMastercheeff
    @TheMastercheeff 5 ปีที่แล้ว

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

  • @davidzap
    @davidzap 5 ปีที่แล้ว +31

    Don't forget to add a mesh collider

    • @lorenzvo5284
      @lorenzvo5284 5 ปีที่แล้ว +9

      or do and be frustrated ;_;

    • @vinnyorlando4930
      @vinnyorlando4930 5 ปีที่แล้ว

      I tired. It doesn’t seem to work.

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

      try with the "is convex" checkbox

    • @vinnyorlando4930
      @vinnyorlando4930 5 ปีที่แล้ว

      @@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

  • @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

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

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

  • @Hello-sq3eh
    @Hello-sq3eh 3 ปีที่แล้ว

    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!

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

    Anyone else having problem when making the size bigger than 218x300? (or any other size that is equal or bigger than this). Triangles wont spawn correctly anymore and loop back around to the start, i have no clue what i am doing wrong.

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

      Nevermind, i have found it. Never knew there was a limit on meshes in Unity. Limit is somewhere around 65000, so this is why my triangles looped back to the first one. Hope someone else isnt this long stuck on this simple thing haha

  • @benjoe1993
    @benjoe1993 5 ปีที่แล้ว

    Best explained terrain generation video out there! Good stuff!

  • @johngrey5806
    @johngrey5806 5 ปีที่แล้ว

    Without further ado, I like this video!

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

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

  • @ZitongWu-jr7bi
    @ZitongWu-jr7bi ปีที่แล้ว

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

  • @333jordyg
    @333jordyg 5 ปีที่แล้ว +9

    Awesome video! How can we re-calculate a mesh after having the player interact with it - digging through the ground like Minecraft, for example?

  • @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

  • @thek1llerbear570
    @thek1llerbear570 5 ปีที่แล้ว

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

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

    Hello I tried to make a bigger a map (400 * 400 ) but when you exceed 256 * 256 vertices you have the "light problem" because vertices are not connected well. Is it because the array cant exceed a max value ?

  • @jens2481
    @jens2481 5 ปีที่แล้ว +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.

  • @someone4422
    @someone4422 5 ปีที่แล้ว

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

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

    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;

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

    How do you turn it into a continuously generated procedural mesh?

  • @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 2 ปีที่แล้ว

      thats just going to make your quad miss 1 line

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

    Hi, I keep getting this error message _[__15:31:07__] Assets\MeshGenerator.cs(40,15): error CS1519: Invalid token '=' in class, struct or interface member declaration_ and I can't fix it.
    This is where it is saying:
    triangles = new int[3];
    triangles[0] = 0;
    triangles[1] = xSize + 1;
    triangles[2] = 1;
    Can anyone help?
    Thanks :)

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

    6:24 i like how you said six it in danish

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

    i tried doing this which much bigger numbers (in my case 1024x1024) and it only did something along the lines of 1024x256. why did it not load the rest?

  • @DualCoreStudio
    @DualCoreStudio 5 ปีที่แล้ว

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

  • @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!

  • @charlotte1924
    @charlotte1924 5 ปีที่แล้ว +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 :) )

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

    How do I make the mesh flat shaded?

  • @nielsostman
    @nielsostman 5 ปีที่แล้ว

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

  • @reedrendered
    @reedrendered 4 ปีที่แล้ว +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 4 ปีที่แล้ว

      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 4 ปีที่แล้ว

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

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

    I just blinked at 2:37 and I was like *What the hell happened here*

  • @ae112r
    @ae112r 5 ปีที่แล้ว +1

    This is exactly what I needed, thank you!

  • @SnowTerebi
    @SnowTerebi 5 ปีที่แล้ว

    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?

  • @Nexus-rt1bm
    @Nexus-rt1bm 4 ปีที่แล้ว

    Nice tutorial, Helped me with mine in three.js

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

    How do you make the mesh show up when not running?

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

    Thanks for this fantastic tutorial!! I was able to get the correct end result, but I was not able to see the orange lines as you did. Where can I enable this visual option in Unity?

  • @jacoblepley9966
    @jacoblepley9966 5 ปีที่แล้ว +1

    Can you make a tutorial on the same thing, but with the ability to import heightmaps?

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

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

  • @obalfaqih
    @obalfaqih 5 ปีที่แล้ว

    Thanks! Always creating interesting tutorials 👌🏻👌🏻

  • @nielsvdmarel
    @nielsvdmarel 5 ปีที่แล้ว

    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).

  • @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!

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

    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.

  • @nickb7170
    @nickb7170 5 ปีที่แล้ว +1

    hey nice tutorial...could you maybe explain how to add new octaves to that mesh/terrain maybe? because i am having a bit of trouble doing that.

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

    This version of CreateShape() centers the terrain at the origin!
    void CreateShape()
    {
    vertices = new Vector3[(xSize + 1) * (zSize + 1)];
    for (int i = 0, z =0; z

    • @serifgungor
      @serifgungor 7 หลายเดือนก่อน

      thank you problem solved

  • @subramanyam2699
    @subramanyam2699 5 ปีที่แล้ว

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

  • @sammyhamdan9534
    @sammyhamdan9534 4 ปีที่แล้ว +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.

  • @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?

  • @Alex-ir3wr
    @Alex-ir3wr 3 ปีที่แล้ว +2

    RIP BRACKEYS

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

      Brackeys is not dead

    • @Alex-ir3wr
      @Alex-ir3wr 3 ปีที่แล้ว +1

      @@rotinoM0 no u dont understand. The brackeys TH-cam channel is dead

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

      @@rotinoM0 the channel is dead 😭