Hello,
I am working on a 2d game in isometric perspective. I have aligned my Tilemap with the A* Graph (as I saw somewhere in this forum) and it seems to have worked correctly. What I am trying now is to iterate through the Graph checking if each node is in the Tilemap, and defining if it is Walkable or not based on that. This is the code I am using (also taken partly from the examples):
public Tilemap groundTilemap;
public Grid grid;
void Start()
{
AstarPath.active.AddWorkItem(new AstarWorkItem(ctx => {
var gg = AstarPath.active.data.gridGraph;
for (int z = 0; z < gg.depth; z++)
{
for (int x = 0; x < gg.width; x++)
{
var node = gg.GetNode(x, z);
Vector3 position = (Vector3)node.position;
Vector3Int currentCell = grid.WorldToCell(position);
var tile = groundTilemap.GetTile(currentCell);
node.Walkable = tile != null;
}
}
// Recalculate all grid connections
// This is required because we have updated the walkability of some nodes
gg.GetNodes(node => gg.CalculateConnections((GridNodeBase)node));
// If you are only updating one or a few nodes you may want to use
// gg.CalculateConnectionsForCellAndNeighbours only on those nodes instead for performance.
}));
}
This is working to the extent that the area of the map that is not inside the Tilemap is not Walkable, while the area that is inside the Tilemap is Walkable. However, inside the Tilemap zone not all the nodes are becoming walkable, but they form this strange matrix:
The cell layout of the grid is configured as “isometric Z as Y”, and this is my Graph configuration:
My doubts are: am I iterating correctly through the Graph? Are the GetNode() and node.position functions used correctly here?
I’m not clear if I’m missing something obvious, since as I understand it if the cells are the same size and aligned in the exact same position this should work.
Thanks for your help.