How Minecraft Works | Chunk Data Generation [C#] [Unity3D]

preview_player
Показать описание
In this video, I go over how I recreated Minecraft's chunk data generation. This series of 'How Minecraft Works' will go over how I recreated many features of Minecraft on my own, and the code behind it so you can learn from the process.

-= Music =-

*****************************************
Music: Dopamine
Artist : DZGRIMX
*****************************************

Operatic 3 - Vibe Mountain
Рекомендации по теме
Комментарии
Автор

The procedural generation code is so beautiful and the whole video feels so comfy to watch, I love these geek videos

Pepius_Julius_Magnus_Maximu...
Автор

This is amazing! I am also making games and im wanting to get into terrain generation and this is really interesting! Good luck with everything:)

PostVROfficial
Автор

Glad to see you hit your 1k subscribers goal

LegoDinoMan
Автор

wow you are awesome, and very smart keep it up!

chewhammer
Автор

Minecraft's terrain generator does a lot more! It doesn't do anything like this! It uses 3D noise, and it uses depth to taper off the density!

oglothenerd
Автор

As much as you think Minecraft is 16 x 256 x 16 per chunk, it is actually divided by 16x16x16 instead, which is then stacked up to work with 3D noise.

sirgrem
Автор

Great video bro, loving the effort you put into these! Shall the subs increase now...

ivansnav
Автор

I feel i have coded myself into a corner, this video gives me a new perspective on how i might want to go about it. (my current problem is that all my chunks only generate in the positive x && z directions);

Gilxen
Автор

My man's reverse engineering a game's source code. I'm not sure if it's legal but I like it.

Smokasaurus
Автор

plz awnser me so i whanted to ask you a bout the perlin noise should i doawnlod it from a site or what i need to do in Unity?

adnanehaddad
Автор

Line 29... HightGen isn't a thing?
Forget that. I'm dumb. Missed a whole line of code.

gamer
Автор

When i wrote public vectore 2 noise scale = new vectore 2.one and so on the next one

chill-guy_-ever
Автор

I have a problem, id does not work

Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class WorldGenerator : MonoBehaviour
{

public Vector3Int ChunkSize = new Vector3Int(16, 256, 16);
public Vector2 NoiseScale = Vector2.one;
public Vector2 NoiseOffset = Vector2.zero;
[Space]
public int HeightOffset = 60;
public float HeightIntensity = 5f;
private int[, , ] TempData;

// Start is called before the first frame update
void Start()
{
TempData = new int[ChunkSize.x, ChunkSize.y, ChunkSize.z];

for(int x = 0; x < ChunkSize.x; x++)
{
for(int z = 0; z < ChunkSize.z; z++)
{
float PerilinCoordX = NoiseOffset.x + x / (float)ChunkSize.x * NoiseScale.x;
float PerilinCoordY = NoiseOffset.y + z / (float)ChunkSize.z * NoiseScale.y;
int HeightGen = Mathf.RoundToInt(Mathf.PerlinNoise(PerilinCoordX, PerilinCoordY) * HeightIntensity + HeightOffset);

for(int y = HeightGen; y >= 0; y--)
{
int BlockTypeToAssign = 0;

if (y == HeightGen) BlockTypeToAssign = 1;

if (y < HeightGen && y > HeightGen - 4) BlockTypeToAssign = 1;

if (y <= HeightGen - 4 && y > 0) BlockTypeToAssign = 2;

if (y == 0) BlockTypeToAssign = 3;

TempData[x, y, z] = BlockTypeToAssign;
}
}
}
}
}

private void OnDrawGizmos()
{
if(TemData != null)
{
for(int x =0; x < ChunkSize.x; x++)
{
for (int y = 0; y < ChunkSize.y; y++)
{
for (int z = 0; z < ChunkSize.z; z++)
{
switch (TempData[x, y, z])
{
case 0:
continue;
case 1:
Gizmos.color = Color.green;
break;

case 2:
Gizmos.color = Color.yellow;
break;

case 3:
Gizmos.color = Color.gray;
break;

case 4:
Gizmos.color = Color.black;
break;
}
Gizmos.DrawCube(new Vector2(x, y, z), Vector2.one);
}
}
}
}
}

Mojzer_