I am spawning a series of cubes/cylinders in a circle, than doing the same thing directly on top of the previously spawned objects, 8 times. This creates a sort of structure, made with Unity elements.
Here is what is currently looks like : https://i.stack.imgur.com/kSnzK.jpg
Currently the objects are laid on top of each other the exact same way each time, so objects are segmented into straight vertical lines, or columns of some sort. I would like to shift the rotation of how each "layer" spawns so that it almost looks like how bricks would be laid.
I have left a comment within the code that hopefully provides some sort of further visual explanation.
public GameObject cylinder;
int pieceCount = 15;
Vector3 centerPos = new Vector3(0, -2.2f, 0);
float radius = 1.21f;
void Awake()
{
float angle = 360f / (float)pieceCount;
for (int layers = 1; layers < 9; layers++)
{
for (int i = 0; i < pieceCount; i++)
{
Quaternion rotation = Quaternion.AngleAxis(i * angle, Vector3.up);
Vector3 direction = rotation * Vector3.forward;
Vector3 position = centerPos + (direction * radius);
Instantiate(cylinder, position, rotation);
}
centerPos.y += .6f;
}
//Currently the structure looks like this
// [] [] [] []
// [] [] [] []
// [] [] [] []
// [] [] [] []
//Ideally something similar to this
//[] [] [] []
// [] [] [] []
//[] [] [] []
// [] [] [] []
}
I thought I understood the math for all this relatively well, but I am having trouble implementing this new feature. I have tried a variety of things, such as multiplying the rotation variable by Eulers, but working with this variable is finicky, and it seems to very easily affect the orientation of my objects, so they no longer stack on top of each other and the structure falls apart.