# How to generate infinite cube world / minecraft terrain with perlin noise?

NOTE: This is NOT Me asking you to give me the code as that would be completely unfair to you and to me, In the sense that i would not be learning anything at all. Or me trying to make a Minecraft / Cube World clone. I am 15 years old and have been using Unity3D for a very long time now, I have become very advanced in Unity’s interface and have taken up Javascript to forward my knowledge in Game development. For a small project i would like to learn first off, How to use perlin noise to generate Minecraft like terrain that is infinite in all directions except down, Down it should be 10 blocks (It’s more of a exploration game then a mining game like minecraft and others) Once that has been achieved (And i know it wont be easy) i would like to also learn how to add different bioms Example: basic and most common is the wasteland, small pools of acid, tiny town like structures that will be made of prefabs i designed or just cube placeholders. I have many more things to ask but this is the most important and difficult wall i have to overcome. Thank you for your time in anwsering my question, Any feedback would be appreciated (Sorry if i misspelled some things my first language is not english)

to generate a 16X16 chunk i use

for (float px = 0; px < width; px ++) {
for (float py = 0; py< width; py ++) {

``````			System.Random rnd = new System.Random();
var Perlin1 = Mathf.PerlinNoise((px+ transform.position.x) /a, b);
var Perlin2 = Mathf.PerlinNoise((py+ transform.position.z) /a, b);

createCube(new Vector3(px + transform.position.x
, Mathf.FloorToInt(Perlin1*40*Perlin2),
py + transform.position.z));

}
}
``````

I have updated the chunk generator now you can set a render distance allowing you to render new chunks prier to you heading to the edge of a chunk

using UnityEngine;
using System.Collections;

public class ChunkMap : MonoBehaviour {
public Transform Chunk;
public Transform player;
int chunksize = 16;
int render_distance = 6;

``````// Use this for initialization
void Start () {
GenerateChunks();

}

void GenerateChunks()
{
Vector3[] chunks = new Vector3[render_distance*render_distance];
bool[] chunksbool = new bool[render_distance*render_distance];

int i = 0;

for(int x=(render_distance/2)*-1;x<render_distance/2;x++)
{
for(int z=(render_distance/2)*-1;z<render_distance/2;z++)
{
int px = Mathf.RoundToInt(player.transform.position.x /16) * 16;
int pz = Mathf.RoundToInt(player.transform.position.z /16) * 16;
px = px+(x*16);
pz = pz+(z*16);
chunks *= new Vector3(px,0,pz);*
``````

_ chunksbool = true;_
* i=i+1;*
* }*
* }*

for(i=0;i<render_distancerender_distance;i++)
_
{_
_
foreach (Transform child in transform)_
_
{_
_ if(child.transform.position == chunks)
{
chunksbool=false;*_

* }*
* }*

* }*
for(i=0;i<render_distancerender_distance;i++)
_ {
if(chunksbool)
{
CreateChunk(chunks);
}
}*_

* }*

* void CreateChunk(Vector3 pos)*
* {*
* Transform chunk = Instantiate(Chunk,pos,Quaternion.identity) as Transform;*
* chunk.transform.parent = transform;*

* }*
* void DestroyChunks()*
* {*
_ int px = Mathf.RoundToInt(player.position.x/16) * 16;
int pz = Mathf.RoundToInt(player.position.z/16) * 16;_

* int renderer = Mathf.RoundToInt(render_distance + (render_distance/2));*

* foreach (Transform child in transform)*
* {*
* Vector2 ch = new Vector2(child.transform.position.x,child.transform.position.z);*
* Vector2 pl = new Vector2(player.transform.position.x,player.transform.position.z);*

* float dist = Vector2.Distance(ch,pl);*

_ if(dist>renderer20)
{*_

* Destroy(child.gameObject);*

* }*

* }*

* }*

* // Update is called once per frame*
* void Update () {*

* GenerateChunks();*
* DestroyChunks();*

* }*

}