- Home /
Rotate corner tiles with bitwise method
Hi there,
I have a level described by an array. This array is then filled with gameObjects.
private var levelArray:int[] = [7,0,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,
0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,
0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,
0,0,0,0,1,1,1,1,1,1,6,6,1,1,1,1,0,0,0,0,
0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,
0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,
0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
var width = 20;
var length = 20;
var pieces: GameObject[ , ];
pieces = new GameObject[width, length]; // creates the object array
for(z=0; z<length; z++){
for(x=0; x<width; x++){
var prefab: GameObject;
prefab = blockPiece[levelArray[z*width + x]];
// Add piece to stage
pieces[x,z] = Instantiate (prefab, Vector3(x,1,(z*-1)), Quaternion.Euler(0, 180, 0));
cP = levelArray[z*width + x];
print(cP);
}
}
I can't figure out how to automatically rotate the corner pieces of my level. I need some kind of for loop that checks the surrounding numbers in the array.
Please help
Will
It looks like you don't use special corner pieces... how should they be rotates? You have "1"-tiles at straight edges negative and positive corners. I can't imagine a tile (which have to be rotated) to fit in all of these positions...
Do you have screenshots of your different tiles?
To do this automatically it's not that easy. The main problem is to deter$$anonymous$$e what's supposed to be inside and what's outside. This can be done by checking the 8 surounding pieces.
It might be much easier when you just use some more prefabs for each rotation (should be only 4) and define them accordingly.
Yeah, need more information about what a rotated corner piece is for instance would better help us to help you.
Thanks for the comments.
I basically have an island with sand, water and corner piece blocks. The corners have id's at the moment 3, 4, 5, 6. They are not defined in the code but each corner or diagonal piece will be set to the id of a diagonal bit. I want to avoid na$$anonymous$$g all these in the map array, so that those edges are worked out automatically.
I have seen it done and it's referred to as the bitwise method, but I have no idea how to implement it. I need to generate a code for each number in the array that describes the 8 surrounding blocks and then I'll check those codes against a list somehow??
Although $$anonymous$$e is simpler as I just want corners and diagonals.
Your answer
![](https://koobas.hobune.stream/wayback/20220613061833im_/https://answers.unity.com/themes/thub/images/avi.jpg)