minecraft like game

I am trying to make something like motherload (similar to minecraft with 3d cubes in 2d world). I am trying to generate cubes in array around 128 * 8192, I tried that with simple 2 for loops like

var dirt : Transform;

private var width : int = 32;
private var lenght : int = 32;


function Start () {

   for(var i = 0; i < width; i++){
       for(var j = 0; j < lenght; j++){
            Instantiate (dirt, Vector3(i, 0, j), Quaternion.identity);
       }
   }
  
}

but it is obviously not affective. I know i have to split it into chunks and than generate chunks with lets say 32 * 32. and than display only chunks which are visible to player. Here I have a problem as I dont know how to do that. Simple destroying them would be a option but problem is how to generate them back exactly how the player dig through them and also there will be more types of blocks and they need to be the same type after regeneration. I read something about saving each block type as one byte. 1 = empty block, 2 = dirt block, 3 = gold… You probably know what I am thinking.

I am not asking for complete script just for help to understand how script should work.

Usually what you want to do is to save only changes made to a chunk and then apply those changes after regenerating the chunk. If you’re using a pseudo random (seed based) generator you will always have the same output when you also give the same input.

What you could do is to (possibly) use a noise generator or cellular automata to generate the world for you and then either randomly place X numbers of ores per chunks or use a cellular automata.

I’ve not tried my self to create voxels in 2D but I know it is possible, and I believe this guide may be of use: [Tutorial] Procedural meshes and voxel terrain C# - Learn Content & Certification - Unity Discussions

Additional you can head over to this thread: After playing minecraft... - Industries - News & General Discussion - Unity Discussions it’s mostly 3D based but it should be as easy to do in a 2D space.

Good luck!

1 Like

Voxels is the answer. If you use Instantiate the physics engine will die pretty quick.

1 Like

Yea I will go with voxels. Maybe I didnt explain it well, it is completely 3D game, but the world wont have any height like minecrafts hills and mountains. I will go through procedural mesh and voxel terrain tutorial and hope it will turned out well. Thank you for your help, if I wont understand something, I will come back :slight_smile: