- Home /
Voxel Cube variety
Hello. I am currently making a voxel game similar to minecraft. I found this script on unity wiki and need some help to add variety. It has forty layers but, is it possible to change the block in each layer? Thank you for your time.
private var rot : Quaternion;
rot.eulerAngles = Vector3(0, 0, 0);
var terraincube: GameObject;
function Start (){
for (var px:float = 0; px < 100; px ++) {
for (var py:float = 0; py< 100; py ++) {
var Perlin1 = Mathf.PerlinNoise(px/30, 76);
var Perlin2 = Mathf.PerlinNoise(py/30, 22);
Instantiate(terraincube, Vector3(py-50, Perlin1*40*Perlin2, px-50), rot);
}
}
}
yes but I wanted to customize my voxel in the differing heights of blocks, not take from $$anonymous$$ecraft. ( not Just Yet :) )
You can't really do voxels this way. This script will create 10,000 separate objects, which is far too many. You need to use the $$anonymous$$esh class to create chunks.
Im sorry, I'm newer to scripting and I do not know how to create chunks using mesh class. I also don't know what mesh class is.
Also, if you can, is there a place I could learn?
Check the Unity Scripting API for information about the mesh class. Generally, the Scripting API should be your first stop when using an unknown class or function. As has been mentioned, $$anonymous$$inecraft and similar games don't create one object per block; this becomes prohibitive performance-wise very quickly (a 100x100x100 world would be 1 million blocks). Ins$$anonymous$$d, a mesh is generated procedurally in a script, and the mesh is divided into chunks to stay below the 65k vertex limit a mesh has.
There are lots of $$anonymous$$inecraft-in-Unity tutorials.
I was recommended this tutorial for voxel map creation. I hope this is helpful. http://forum.unity3d.com/threads/tutorial-c-voxel-terrain-with-infinite-terrain-saving-and-loading.293340/