- Home /
The question is answered, right answer was accepted
Help with generating Chunks!
Hi, I am making a voxel, minecraft-style, but cannot figure out how to dynamically spawn chunks. Every tutorial I found was taking about spawning chunks from prefabs, but I am using PerlinNoise to generate the chunks into the world as the player moves.
This is my method for generating one chunk: void GenerateChunck(int xStart, int zStart) {
ChunckSize = 16;
xStarters.Add (xStart);
zStarters.Add (zStart);
xEndings.Add (xStart + ChunckSize);
zEndings.Add (zStart + ChunckSize);
for(int x = xStart; x <= xStart + ChunckSize; x++) {
for(int z = zStart; z <= zStart + ChunckSize; z++) {
//Instantiate Grass based on size and parent it to TerrainManager
var instantiation = Instantiate(Grass, new Vector3(x, 0, z), Quaternion.identity) as GameObject;
instantiation.transform.parent = transform;
//PerlinNoise
height = Mathf.PerlinNoise((x + seed) / scale, (z + seed) / scale);
FinalY = Mathf.RoundToInt(height * scaleModifier);
instantiation.transform.position = new Vector3(instantiation.transform.position.x, FinalY, instantiation.transform.position.z);
GrassLocations.Add(instantiation.transform);
}
}
//Generating all levels below grass
GenerateDownward();
}
}
Any help would be appreciated!
-Qo2770
So, where is your problem? Using prefabs for chunks just means that you isntantiate a gameobject that has a $$anonymous$$eshRenderer, $$anonymous$$eshFilter and $$anonymous$$echCollider and then assign the texture atlas material to the Renderer, and the generated mesh to the Filter and Collider.
Ohh, I understand. Thanks so much, I will look into it. Sorry for being so nooby, but I'm just learning Unity, -Qo2770
We all have to start somewhere :)
Here is a handy, if comprehensive, thread for all things Unity-$$anonymous$$inecraft-related.
http://forum.unity3d.com/threads/after-playing-$$anonymous$$ecraft.63149/
Follow this Question
Related Questions
how to create chunks in voxel terrain generation 1 Answer
How to load stacking chunks on the fly? 1 Answer
Flowing water in my voxel terrain 1 Answer
Terrain Chunk loading 1 Answer
Tiled Terrain 0 Answers