Hello
Been trying to get this working for hours, googling all sorts of dead ends that dont seem to cover what I need.
I am trying to write my own autotiler instead of using the 2d extras as I have some other requirements like sprite swapping based on some other things.
So for right now im just trying to get some basic autotiling working first with code.
Looking at the options you can go with 47 tiles covering every configuration, or 16 tiles that covers almost everything but reaquires atleast 4 tiles together (which im happy with) So i settled on trying the below to test things out.
It suggest you can use bit masking (looking at the neighbours) to calcualte an index for which sprite this tile should have.
tile_index = topLeft + 2 * topRight + 4 * bottomLeft + 8 * bottomRight
I coded this up as
int TR = TileValue(tilemap, position + new Vector3Int(1, 1, 0)) ? 1 : 0;//Top Right
int BR = TileValue(tilemap, position + new Vector3Int(1, -1, 0)) ? 1 : 0;//Bottom Right
int BL = TileValue(tilemap, position + new Vector3Int(-1, -1, 0)) ? 1 : 0;//Bottom Left
int TL = TileValue(tilemap, position + new Vector3Int(-1, 1, 0)) ? 1 : 0;//Top Left
int mask = TR + BR * 2 + BL * 4 + TL * 8;
tileData.sprite = spriteList[mask].sprite;
TileValue just return whether a tile of this type exists in that position.
Moving the sprites around in my list I was able to generate the below.
As you can see its not quite right!, and I think its becuase I am not accounting for the cardinal neighbours!
But a bit mask with 8 neighbours instead of 4 is going to have 256 permitation ( Cut down to 47 unique as many are identical, which is too many. How do i bring that down to just the 16 tiles I have ?
Can anyone offer any insight or point me in the right direction please.