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.
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!
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;
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);
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
@@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;
@@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
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.
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.
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
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)];
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. 👍
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).
@@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
@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
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!
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.
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)
@@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. :)
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!
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()).
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.
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);
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 :) )
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
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".
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à.
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.
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.
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 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.
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!
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;
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
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 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
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?
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!
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
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..
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.
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).
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!
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
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.
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.
“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.)
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.
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 😉
TIP: If you are creating a massive terrain (big xSize and zSize) do mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; UNDER GetComponent().mesh = mesh;
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
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?
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?
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.
Dang now this is how you make a tutorial
I watch it 3 times in a row
Its entertaining
1:25 i ain't killing my first triangle! *puts script in a backup folder and hugs it protectively*
I feel attacked by this
dang relatable
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!!
I just put it in the comments so it can live on in the code
You could've just commented it out.
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!
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;
it don't work for me. i've got the message "Object reference not set to an instance of an object"
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);
@@001zeal Thanks Yasha!
@@001zeal What is vertexFieldSize?
You need to set the uv array size:
uv = new Vector2[(xSize + 1) * (zSize + 1)];
i miss brackey
Same we all do
well he is back!
@@fraaannn783 No unity so meh
It's impressive how you've been able to explain this in 13 min. Amazing
I really like that you are slowing down when explaining topics. It is really helpful thanks
"Without further ado"
"But 1st Skillshare ad"
FINALLY!!! Please do more procedural tutorials!
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.
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
Did you ever figure out why? What was the bug. I am having the same issue
@@nerditstudios3457 same issue, did you know of to fix this ?
@@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;
thank you! could you make a part 2 of this video? like adding color via height and saving landscapes?
I recommend you watch this series, if you want to know more about landmass generation ruclips.net/video/wbpMiKiSKm8/видео.html
Saving landscapes sounds cool, but i guess you could just record all the values in the array and save those.
@@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
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.
@@RugbugRedfern You wouldn't be saving the landscape then, just the noise, there's more to the landscape than just the noise.
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.
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
This is why I link to your channel whenever someone asks how to do stuff in unity. Thanks!
Amazing Tutorial! Pretty well explained! I like to see a part 2 with colors and saving the landscapes. 😄
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
Thanks I didn't know where i messed up but now i know!
It isn't working like for proper generation, it exists but as a flat plane
I have no idea about coding and stuff but your channel is very interesting
Brackey's videos are so relaxing and enjoyable
I love how you just say "yaay" when you are done
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. 👍
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).
@@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
I don't understand but ok thanks
@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
i = z * zSize + x
Seriously you are insane ! You are amazing ! I learn so much with your videos. Keep on the great job !
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!
Pretty well explained, thanks! What will be the NEXT step in this topic?
erosion algorithms plz XD
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.
@@rubixcube6 Search "Sebastian Lague Procedural Landmass Generation", first result
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)
@@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. :)
Best explained terrain generation video out there! Good stuff!
I was waiting for this tut! Thank you!
after 5 years, I want to say once again, thank you
mans needs to make a masterclass right fkn now brackeys you are great
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!
i got stuck in the gizmos because they were turned off on the scene! beware of that if you dont see the gizmos.
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()).
I once deleted event system in scene and 2 days was trying to find reason why I can't press button
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.
Had to watch at 0.5 speed to keep up 😂
I really like this video. You make things easy and I like your art style.
This really demystified this process, thank you
I love the perlin noise you added into the whole flat terrain thing you explained it well
Another awesome video!! If you like text tutorials, you can also see catlikecoding tutorial on terrain generation, which is much similar to this
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);
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 :) )
Didn't see this coming, thanks Brackeys :)
- Mislav
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
Looks cool! Mathf.PerlinNoise is one of my favorites! 👍🤓🧡
Without further ado, I like this video!
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".
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à.
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.
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 😃
Very useful information, I needed this a lot as I want to mess around with Voxels in Unity and world generation.
Thanks! Always creating interesting tutorials 👌🏻👌🏻
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.
This is exactly what I needed, thank you!
And now to add a Collider that actually fits the mesh :P
Add a mesh collider to your object and add this line inside void Start(), after updateMesh();
GetComponent().sharedMesh = mesh;
@@iustall huh, that easy :D Thanks!
Lifesaver
A nice and easy to follow video, I'd been thinking how is this possible for some time now.
Great video. I wanted to learn procedural mesh generation... Ended up making game that procedurally creates terrain based on an image.
5:55 you can also define the Array just like this: triangles = new int[3] { 0, xSize + 1, 1 };
Don't forget to add a mesh collider
or do and be frustrated ;_;
I tired. It doesn’t seem to work.
try with the "is convex" checkbox
@@davidzap yea.. i figured that out.. i had gotten confused and thiught that was force rigidbodys only
or you make a own colliding system and stop lagg spikes of occouring on a huge mesh
nice trick with putting the i in the for loop! Never thought about doing it like that...
I am at 0:57 and I already clicked 👍just for that wonderful smile
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++)
did u find a fix?
@@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.
@@alainray I wish I had seen this comment so much sooner than I did, would have saved me so much time!
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!
Brackeys: Without further ado, let's get started!
Also Brackeys: But first, this video is sponsored by...
I can't believe I just learned you can have multiple local variables in a for loop
same
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;
You uploaded the video while I was sleeping there was 3;00 AM
Cool vid bro! Love your content!
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
You are a great teacher breackies.. You can make learning awesome. Tnq very much :)
watching this I just had a flashback to doing 2D FEA analysis when he got to triangles
Nice tutorial, Helped me with mine in three.js
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!
Hey how did you do this in ue4 blueprints?
@@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
@@jens2481 ah ok well thanks.
Very interesting topic. Good job the Danish king!!
Very good video
You don't need "i", you can express the index through z*(xSize+1) + x at 4:00
i is more readable. I'd prefer to walk into Brackeys' code rather than the option of z*(xSize+1) + x
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?
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!
@Brackeys,
You again save my life :)
RIP BRACKEYS
Brackeys is not dead
@@rotinoM0 no u dont understand. The brackeys RUclips channel is dead
@@rotinoM0 the channel is dead 😭
So, without further ado let's generate some terrain. But first this video is sponsored... 🤔
Thank you for the great content!
Thanks for the new video mate :)
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
thats just going to make your quad miss 1 line
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 :)
hello, could you make a tutorial about marching cubes terrain? I would like to edit terrain like digging in game. Thank you.
Could you please make a Tutorial on Generating a 2d Terrain, like in the game Terraria?
well, with something like that, all you would need to do is rotate it 90 degrees, and morph the top
however, it would not be the greatest idea to use a mesh for that depending on world size. 2d games suffice fine with sprites
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..
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.
Marching squares. Is what you want
WOW.. Just wow. Thanks you so much!
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).
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!
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
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.
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.
@@icec00l3d5 getting what to square up? What's in the shape of a rhombus?
@@edgunther8136 Sorry I was vague but I managed to fix it, ty
Brilliant! Thanks for the video.
YES exaclt what i was looking for cheers
Put these in a playlist or link them by a tag! It's a mess to find them together.
nice woodwood hoodie!
“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.)
I have the error Index out of range exemption. What do I have to do? It won’t load the z koordinates
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.
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 😉
Note that this will affect your performance if the mesh is large
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.
TIP: If you are creating a massive terrain (big xSize and zSize) do mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; UNDER GetComponent().mesh = mesh;
Thanks
I'm 2 years late, but thank you!
For some reason this works fine up to 200x200 but when i try 1000x1000 it creates only half of the rectangles
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.
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
@@PraYogiz that would make sense ill give it a try
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.
Hey, Code Monkey has a similar video on this: ruclips.net/video/YI-18iApelA/видео.html
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?
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?