I’m looking for the best approach to manage a large terrain grid (8x8 tiles, each 1000m²) using A* Pathfinding. Any advice on optimizing performance and accuracy?
I’m using A* PRO to draw some roads and path over the terrain, basically shouldn’t be complex, but the gird that I’m able to achive is 1024*1024 with a cell of 7.8125.
So I’m using AstarPath and when I init the grid I try to get it smaller but didn’t work:
float worldSizeX = _terrainGrid.GetLength(0) * _terrainGrid[0, 0].terrainData.size.x;
float worldSizeZ = _terrainGrid.GetLength(1) * _terrainGrid[0, 0].terrainData.size.z;
float nodeSize = 2;
int graphWidth = Mathf.RoundToInt(worldSizeX / nodeSize);
int graphDepth = Mathf.RoundToInt(worldSizeZ / nodeSize);
gridGraph.SetDimensions(graphWidth, graphDepth, nodeSize);
gridGraph.center = new Vector3(worldSizeX / 2f, 0, worldSizeZ / 2f);
gridGraph.is2D = false;
Despite explicitly setting float nodeSize = 2;
the cell size remains around 7. I checked the calculations, but I can’t figure out why the grid isn’t reflecting the expected resolution. Could it be an internal limitation of A* or something I’m overlooking.
So maybe a better solution could be to create a grid for each terrain tile, isn’t it?
The terrain is procedurally designed, so the roads have to, that’s why I thought A* would be a good solution, but the grid is too big and lack of details, so often fails on founding a valid path.
Maybe adding a RecastNavmeshModifier would improve performance and helps?
I’m quite lost.
Any advice is very welcome
- A* version: 5.3.7
- Unity version: 6000.1.5