Hello everybody and welcome back to how minecraft works after a little mental retreat in developing some games i have now regained motivation to continue making tutorials and keep going and for the first tutorial that i’ll make after a long break is finally put a cap onto this tutorial series going over voxel Terrain generation by finally showing you how infinite terrain generation works in order to make the terrain quote-unquote infinite we need a reference point to generate chunks around if the point moves new chunks will be loaded and old chunks will be unloaded to keep the reference point at The center of chunks generated in the game to give the impression of infinite terrain so let’s get to coding immediately create a new c sharp class called infinite terrain generator in this class create four variables in the start method initialize the generator instance and chords to remove list Now in the update function copy down the following code every frame we get the player’s position and convert it to chunk coordinates by dividing the x and z components by the chunk size on the horizontal axis next the code will store every active chunk coordinate in a dictionary into The chords to remove list after that using a for loop that iterates over a 2d grid the code will iterate over coordinates that are expected to have active chunks if the coordinate is not within the active chunk dictionary it will call a create chunk function and it will remove The current coordinate being looped over from the quartz to remove list finally the last loop will destroy the chunk coordinates left in the course remove list by removing it from the active chunks and destroying it to de-allocate the no longer needed chunk once you are done writing all this code The infinite terrain generation class is complete we now have to do some changes to the world generator class to finally get things going first create the following dictionaries initialize the dictionaries in the start function and create a material variable to store the texture atlas material that you will apply to your chunks Next up let’s separate the data generation code into its own function do we can also remove the temp data variable and separate the creation of the chunk game object into its own function also do in this function since it will be called quite a bit of times in the long run Instead of creating a new instance of the chunk mesh jar store one instance in a variable that is initialized in the start function now in the start function create a 2d for loop system that will create a 2×2 grid of chunks to give the infinite terrain generator something to start working off of And with that line of code written infinite terrain generation has been successfully implemented if you wish to add in a player controller you can click on the card at the top right of the video to view a quick and easy implementation of a character controller in your unity game Now back in unity to see the infinite terrain generator do its magic create a default cube as a placeholder and assign it as the player object on the infinite terrain generator now if you click play and move the cube around you can see chunks unload and load based On the cube’s position and render distance the large performance drops can be solved using certain optimizations and this part will be taken care of in the next video so like and subscribe and i hope to see you all in the next video goodbye Video Information
This video, titled ‘How Minecraft Works | Infinite Terrain Generation [C#] [Unity3D]’, was uploaded by Rytech on 2022-04-23 20:17:17. It has garnered 3105 views and 86 likes. The duration of the video is 00:07:30 or 450 seconds.
In this video, I show how to implement the infinite terrain algorithm used in Minecraft!
Join my Discord! ► https://discord.gg/jrRJgfBz2y
-= Chapters =-
0:00 Intro/Explanation 0:40 Implementing Infinite Terrain 6:53 Expected Result/Outro
-= Music =-
***************************************** Music: Dopamine Artist : DZGRIMX link to the video: https://youtu.be/3S6uyNk9HpY channel: https://www.youtube.com/channel/UCBhW… *****************************************
Operatic 3 by Vibe Mountain Clover 3 by Vibe Mountain