- Home /
Code based 3d multiple cube instantiation
Hey guys, I have an idea I'm looking for a little bit of input on.
I'm in the midst of making a game where I want to generate a giant 3d cube. This cube would be made up of smaller individual cubes equidistant from each other, say for sake of argument 50px. So basically you would see a vast amount of cubes acting as one to form a greater object.
I have several ideas on how to tackle this, but I'm trying for smaller. I'm almost certain I can achieve what I want by setting up one base position and having everything spawn/instantiate out from that point; say with several for loops. However, the mathematics involved in this seriously hurt my head.
I was wondering if anyone would be kind enough to help out? It would be greatly appreciated.
Thanks.
Answer by Jiro-Ng · May 02, 2014 at 02:01 AM
// (x, y, z) is the starting position
for(int i=0; i<row; i++)
{
for(int j=0; j<column; j++)
{
for(int k=0; k<depth; k++)
{
//instantiate
//cube position = (x + i*distanceBetweenCube, y + j*distanceBetweenCube, z + k*distanceBetweenCube)
}
}
}
Your answer
Follow this Question
Related Questions
Instantiating prefab at child (spawnlocations are arrays) 2 Answers
instanstiate Spawns more then one objec 0 Answers
Spawn from array 2 Answers
2d spawning problem 1 Answer
Spawner with max enemies 2 Answers