How to limit pathing to 90 degree angles (no diagonals)

Hello everyone,

Currently implementing A* pathing on a top-down RPG. I have everything setup and it’s working, but I’m wondering how I can make it so that my characters can only move in 4 directions (up, right, down, and left). In other words, if you think of a triangle, the player would walk along the bottom and side edge to go from one point to another, rather than crossing the hypotenuse. Is that possible with this library?



If you’re using a grid graph you can start by setting the amount of connections from 8 to 4.
This will make it so that only the GraphNodes left right top and bottom are connected to the current GraphNode.

For movement it’s a bit different. If you’re using the AILerp movement script there should’t be any changes needed. For AIPath and RichAI you’ll want to modify the UpdateRotation funciton. And make it snap to the closest 90degree angle.

Furthermore you may want to change the A* Inspector -> Settings -> Heuristic to Manhattan to get more axis aligned paths. See for more info.