I have a system working for building a custom object out of blocks in a 3D grid environment. I manually set the size of each piece in a Vector3 and then add it like so:
public void AddToGrid (Vector3 gridPos, GunPart _part) {
//adds a reference to an object for every space it occupies on the grid
int x = (int)gridPos.x;
int y = (int)gridPos.y;
int z = (int)gridPos.z;
for(int sx = 0; sx < _part.size.x; sx++){
for(int sy = 0; sy > -_part.size.y; sy--){
for(int sz = 0; sz < _part.size.z; sz++){
//adding the part at XYZ
gunGrid[sx + x, sy + y, sz + z] = _part.gameObject;
}
}
}
}
If I want to be able to rotate the pieces, I’m not sure how to take the euler angles and apply it to that size to accurately shift the X,Y and Z of the size. The origin of each piece is in the top/left/back so I’d also need to know where it’s orienting and how to move along the grid accordingly. I’ve tried to google this but found nothing.