ProceduralGridMover with Procedural tiles?

You also need to know the origin point for the chunk. How is that stored?

Each chunk has 2 variables called chunkPosX and chunkPosY. They aren’t in world coordinates though so you would have to multiply them by the chunk size.

So you would have to do something like

Chunk chunk =[dataIndex].x, (int)nodePositions[dataIndex].z);
int gridX = bounds.min.x + dataX;
int gridZ = bounds.min.z + dataZ;

int chunkCellX = gridX - chunk.chunkPosX*25;
int chunkCellZ = gridZ - chunk.chunkPosY*25;
int chunkCellIndex = chunkCellX*25 + chunkCellZ;
Tile t = chunk.chunkTiles[chunkCellIndex];

This assumes that chunkPosX=0 and chunkPosY=0 implies that the chunk starts at the world origin. And that the node size is 1 world unit.
Might be easier for you to write a world position to tile function? Instead of just world position to chunk.

I managed to get it working! In a different way though, I realized since I have the positions of your grid nodes in world position I could just use my GetTileAt() method which simply takes a world position and gives a Tile from that position, going into chunks and all that.

Which made it as simple as this:

Tile t =[dataIndex].x, (int)nodePositions[dataIndex].y);

nodeWalkable[dataIndex] = t.terrainType.isWalkable && t.buildingType.isNull;

Though am having a bit of a smaller issue, the graph is off by 0.5 or something, which you can see here:


You can probably want to add (0.5, 0.5) to the graph center in the grid graph settings. That way it will be aligned with your underlaying data.

That fixed it! Thank you so much! This will work very well :smile:

1 Like

How would I recalculate a single node?


You can do something like Bounds((Vector3)node.position, new Vector3(1, 1, 1));

That will recalculate the graph in a small box around a given position.

Note that updating the graph has some overhead, so it is much faster to recalculate a large group of nodes at the same time compared to updating each node individually.

Thank you! It works, though yeah I do notice some overhead.