For anyone getting a flat mesh without any triangles on it - make sure you turn on 'Selection Wire' under Gizmos in the top-right of your Scene View. :) P.S. You da man, Rus!
@CodingWithRus Жыл бұрын
Ha! Thanks Edmund, and thanks for spreading the knowledge! A really nifty and useful gizmo!
@SudopiaGames Жыл бұрын
Thank you so much
@fabiansinger43003 жыл бұрын
YO this guy is underrated
@CodingWithRus3 жыл бұрын
Thank you!
@aichayasmine21684 жыл бұрын
You explain things so easily thanks so much for this!
@CodingWithRus3 жыл бұрын
You're so welcome!
@demarcorr2 жыл бұрын
my face when im 9 years into c# and i just learned i can declare and initialize multiple values in the for loop. It makese perfect sense now, ive just never tried it
@LuRybz4 жыл бұрын
Thank you for the content. Rus, some suggestions: - Managing the meshes in multiple chunks for performance - Changing the mesh at runtime (the sims Building mode/ Roller Coaster Tycoon 2)
@CodingWithRus4 жыл бұрын
On it! I've added these to the list 😁
@orderlyhippo15693 жыл бұрын
Deserves more likes/views
@SaadAli-pv6fh4 жыл бұрын
Great series man
@CodingWithRus4 жыл бұрын
Thank you! :)
@diyguild13273 жыл бұрын
What is your into song? It's so chill. Also thanks for the video. The more I work meshes the more I'm starting to get the hang of working with them from code
@CodingWithRus3 жыл бұрын
Hey - happy to hear! sorry I don't really remember the song name as I've made it a long time ago and switched computers. Maybe try to Shazam it? Rus
@diyguild13273 жыл бұрын
@@CodingWithRus Shazam came in clutch Pomelo - Jobii
@assasino4043 жыл бұрын
Love the series and this mesh generation is helping me a lot! I did want to ask, how could I spawn objects just like in the procedural placement episode 3 video but here, on mesh. It seems like I'm getting an error when I'm trying to move things across from the code from episode 3 to my mesh generation with the ".transform.position)" line as I don't think I'm clearly stating where I want the object to be positioned maybe?
@CodingWithRus3 жыл бұрын
Hey! Use the vertices as the point to spawn them in! If you share the code I can take a look. Thanks!
@assasino4043 жыл бұрын
@@CodingWithRus Here is my the code: using System.Collections; using System.Collections.Generic; using UnityEngine; public class MeshGenerator : MonoBehaviour { //defining our world size public int Worldx; public int Worldz; public GameObject objectToSpawn; //Create a mesh to be our new mesh private Mesh mesh; private MeshCollider meshCollider; //Define the arrays needed for the mesh private int[] triangles; private Vector3[] verticies; // Start is called before the first frame update private List blockPositions = new List(); void Start() { mesh = new Mesh(); GetComponent().mesh = mesh; meshCollider = GetComponent(); GenerateMesh(); UpdateMesh(); blockPositions.Add(verticies.transform.position); SpawnObject(); } void GenerateMesh() { triangles = new int[Worldx * Worldz * 6]; verticies = new Vector3[(Worldx + 1) * (Worldz + 1)]; for (int i = 0, z = 0; z
@CodingWithRus3 жыл бұрын
@@assasino404 Nice, looks good! I've amended the ObjectToSpawnLocation method and got rid of a few things:) I've recently gotten a new laptop and don't have unity installed on it yet so having to do this on notepad (yikes). I've added comments so that you can easily follow along in case I've missed something. // Create a list to hold our newly spawned Items in our world. List spawnedLocations = new List(); // Here, we are calling for the gameobject (trees) to be spawned in random positions on the blockpositions (cubed grass) private Vector3 ObjectSpawnLocation() { // Get a random point from our vertices array int rndIndex = Random.Range(0, vertices.length); // Assing a random Vertex from our vertices array to newPos Vector3 newPos = vertices[rndIndex]; // Amend our yAxis to not be in the ground newPos.y + 0.5f; // Run a quick check to see if this newly added position already exists in our list if(spawnedLocations.Contains(newPos){ // If it does, re-call method to generate a new point. Debug.Log("Whoops - This space is already taken! Generating a new point!"); newPos = ObjectSpawnLocation(); } //If the new location doesn't exist add it to our list spawnedLocations.add(newPos); // Return the newPos return newPos; } } Hope this helps - if you're having any more issues, I can send you over the whole code with those changes instead of the specific method :) Rus
@assasino4043 жыл бұрын
@@CodingWithRus Hey Rus, I really appreciate all your help it means a lot! I hate to ask this but I'm getting an error when adding this method in. which is "Assets\MeshGenerator.cs(126,46): error CS1026: ) expected " which is the "if(spawnedLocations.Contains(newPos){" line. I'm not sure if it's me because I've been staring at code the entire day haha. I tried adding a ")" at the end of the line thinking it may work but that only breeds more errors.
@CodingWithRus3 жыл бұрын
@@assasino404 Hey - Just installed Unity; gonna have a look through your code and see whats up, that method should't be throwing an issue though :/ Will post a link to a gist once done.
@leikiamyrini88493 жыл бұрын
Can you combine this with the infinite terrain video?
@CodingWithRus3 жыл бұрын
With a few adjustments and you should be able to! It's a different process of the generation though. I'm considering making a video around this! Thanks.
@Thesupperals Жыл бұрын
The code is sound. Unfortunately, I'm coming across an error when you designate your world x and world z larger than 250. I get a rectangle instead of what should be a square. Also, Z fighting/interlacing occurs.
@CodingWithRus Жыл бұрын
Hey, the reason you're getting an error is because of the max amount of vertices a mesh can hold. As a mesh is made up of a 16-bit index buffer, it only supports up to 65,535 vertices. Thanks for the comment!
@anuraagsaxena79422 жыл бұрын
I think there is error in code For the triangles for loop Worldx should be added rather than Worldz To go to the next row
@CodingWithRus2 жыл бұрын
Hey! Shouldn't be as the code that you see if the one that's written :)
@beweldadon2 жыл бұрын
It didn't work for me, I've copied the code completely and followed every step and don't know what I am doing wrong. Was there a step I missed?
@CodingWithRus2 жыл бұрын
Hi, Are there any errors that you're seeing?
@beweldadon2 жыл бұрын
@@CodingWithRus no That's the weird thing
@CodingWithRus2 жыл бұрын
Can you see the mesh field populated? You may have inverted the mesh, move the camera underneath and have a look if you can see it
@beweldadon2 жыл бұрын
@@CodingWithRus no, I can't see any mesh, top or bottem
@CodingWithRus2 жыл бұрын
Have you attached your mesh to a gameObject?
@ductrungg0110 ай бұрын
Guys, change Worldz in his code to Worldx : int tris = 0; int verts = 0; for (int z = 0; z < Worldz; z++) { for (int x = 0; x < Worldx; x++) { triangles[tris + 0] = verts + 0; triangles[tris + 1] = verts + Worldx + 1; triangles[tris + 2] = verts + 1; triangles[tris + 3] = verts + 1; triangles[tris + 4] = verts + Worldx + 1; triangles[tris + 5] = verts + Worldx + 2; verts++; tris += 6; } verts++; }
@iagopaulo24457 ай бұрын
Underrated comment, saved my life thanks dude!
@gorkemdener-wf3ky7 ай бұрын
great correction I was looking for that issue !!
@leafgamedev77093 жыл бұрын
why not work for me? i am using unity 5 please help
@CodingWithRus3 жыл бұрын
Hi, what exceptions are you seeing? - Rus
@SaadAli-pv6fh4 жыл бұрын
Also do a video on sprites
@CodingWithRus4 жыл бұрын
On it! (flex)
@SaadAli-pv6fh4 жыл бұрын
I have a script which add gradient to any sprite and we can animate the gradient i believe its using the vertex coloring at runtime.. so if possible can you do a video ... I can send you the script
@kirayt2492 жыл бұрын
I GOT SOME MESH BUT BETWEEN LIKE FEW GRIDS THERE AN EMPTY ONE WTF HOW TO SOLVE IT PLZ
@kirayt2492 жыл бұрын
AND THAT ONLY HAPPEN WHEN I CHOOSE DIFFERENT WORLDZ AND WORLDX WHEN THEY MATCH EACH OTHER THERE NO EMPTY GRIDS
@CodingWithRus2 жыл бұрын
Hi, it sounds like you're exceeding the vertex limit of the mesh. No caps next time please ;). Rus
@LM-cc7qz3 жыл бұрын
bruh imagine straight up copying brackeys code and then making the same tutorial with it without even mentioning that you "borrowed" their code.
@CodingWithRus3 жыл бұрын
Hi, I've seen brackeys tutorial but can assure you there was no code stealing. Can you show me a different way of generating a mesh? The formula is the same throughout to generate a plane but open to see a few suggestions :) Rus