There is an easy solution to this, but it will require some extra calculation. By finding the best direct lines that does not intersect with obstacles during the backtracking we can get a better looking path and possibly a shorter path than othewise. Direct lines are always the shortest way of getting from A to B.
Below is an image of how this method is in action. The gray lines that are generated during the tracing for the goal are the foundation for the backtracking. It generates direct lines where the yellow tiles are the endpoints for the lines, and can be used as waypoints for the path. The brown tiles are the actual traversion between the waypoints towards the goal.
Below is a ZIP file containing the program (written in pascal) along with an executable for you to try out.
Code and executable for direct line pathfinding (11082 bytes)
![]() |
john@lis.pitt.edu |