A Star Pathfinding

363 views Asked by At

I've implemented the standard A* Pathfinding algorithm and have it working fine on a 2D grid.

My question is, is there a way to weight the lines so they take the "straightest" path instead of the potential shortest path which it currently takes. So instead of the lines taking the short path and moving in a zigzag pattern they try to find a right angle first.

Any links to resources or advice would be much appreciated!

1

There are 1 answers

0
mGuv On BEST ANSWER

Do you mean they'd move diagonally on the grid? All you'd have to do is open up the node expanding code to also expand (+1, +1), (-1, -1), (+1, -1) and (-1, +1), turning it into orthogonal instead of cardinal. If your A* algorithm is correct, they will favour a single diagonal move over say a east then north move.

If you mean to move across larger areas freely, then that is slightly different and harder to do.