Hello! The AStar package is brilliant, but I’m coming up against a real challenge involving “stitching” the edges of my grid to the opposite edges. I’m using the free version, but perfectly happy purchasing the package if the best solution is only available with Pro. (I’ll probably purchase it either way to show support, but I digress…)
I’m making a 2d RTS game with maps of arbitrary sizes. This world repeats infinitely when panning the camera, and pathfinding should be able to navigate around the map edges as well. I actually came up with a “solution” very similar to the answer posted in Wrap paths around plane, but that answer is 5 years old (!) and I’m wondering if there’s a better way!
Ultimately, I’m using this to stitch together the edges of my world:
node.AddConnection(neighbor, 0);
neighbor.AddConnection(node, 0);
There’s still a a couple problems with my solution, and I’ve ordered them here from highest to lowest priority:
- The GridGraph doesn’t seem to understand areas connected to far edges. Calls to
ABPath.Construct(from, to)
will fail as expected when trying to navigate to these areas, but I can’t usePathUtilities.IsPathPossible
when they’re all considered one area. This makes it problematic to narrow down a potentially large search space of in-area targets. See:
(You can see my extra connections overlayed on top of the standard ones here)
All of the areas in dark purple are considered the same, even though the single island that bridges all four corners is technically in a separate area. The nodes on that island are not reachable from the larger purple area (ABPath.Construct
fails). I’ve tried making calls to FloodFill()
and FloodFill(node)
@ (0,0), but they silently fail to detect these separate areas.
-
Disabling heuristics was the only way to get the units to accept the stitched paths. They will begrudgingly follow it if I make the area behind them unwalkable. I set a zero cost, but I can’t seem to get it to treat my
AddConnection()
s as neighboring nodes. It really wants to use(node1.position - node2.position)
, and since they are physically far away, that cost is calculated as being very high. -
I’ve had to implement my own “teleport” logic when a unit approaches one edge and intends to traverse to the other. I do this by looking ahead at
path.vectorPath[currentWaypoint+1]
to detect and big, suspiciously world-sized jumps in the X, or Y (or both) directions. Is there a better way?
I’m not exactly sure what NodeLink2 does - is that my answer?
I’m also willing to use proxy pathfinding geometry (torus, perhaps?) that exists separately from the scene entirely. I could write a translation layer that converts Game (X,Y) to Clever Pathfinding Shape (X, Z)… but I didn’t want to commit to that just yet.
Thank you for any help you can give!