Using Grid Graph with A* Pathfinding on version 4.2.17
.
Trying to build a road system with the package. Relying on the grid graph and using ABPath to construct a path from point A to point B in the world. Managed to avoid obstacles and technically “go around” them but the path that I get in the end looks like in the screenshot (red line drawn by Gizmos). Also worth noting that at some corners, the node goes in between the cells on the grid which cuts the path on points where it should be a curve.
I would like to achieve paths such as presented by green lines in the screenshot. I tried using modifiers but all of them are simply smoothing the paths which is again not what I need. Then I jumped on creating my own custom modifier, but had no luck with that unfortunately.
The following function gets the nodes for the start-end points:
public Vector3Int[] GetNodes(Vector3Int a, Vector3Int b) {
Vector3 startWorld = grid.CellToWorld(a);
Vector3 endWorld = grid.CellToWorld(b);
List<GraphNode> result = null;
ABPath path = ABPath.Construct(startWorld, endWorld, delegate (Path _p) {
ABPath p2 = _p as ABPath;
result = p2.path;
});
AstarPath.StartPath(path);
AstarPath.WaitForPath(path);
path.BlockUntilCalculated();
HashSet<Vector3Int> uniqueNodes = new HashSet<Vector3Int>();
if (result != null) {
foreach (GraphNode node in result) {
Vector3 nodePosition = (Vector3)node.position;
uniqueNodes.Add(grid.WorldToCell(nodePosition));
}
}
roadPathNodes = uniqueNodes.ToList();
return roadPathNodes.ToArray();
}
I also tried relying on post processed path by getting vectorPath (used raw or with modifiers) but no luck. Any pointers where I can go from where to make this possible?
TLDR; Trying to make paths more L, 90 degree angled, shaped - need pointers on what to try.