Can I reduce the Manhattan zig zag?

I’m using a Manhattan heuristic and four connections to get my seeker to turn at right angles (so it only moves North, South, East, and West to get to where it needs to go). This works, but the paths generated tend to involve many rapid turns, producing a zig zag effect:

Ideally, in an open area like that, it would be great if the path were a simple “L”, with only the one turn, but even just reducing the number of unnecessary turns would be great.

Is there a way that I can reduce/eliminate the zig zagging when it isn’t necessary for finding a path?

Thank you.


Try experimenting with the Heuristic options in the pathfinding settings.
Definitely set it to Manhattan instead of Euclidean and possibly reduce or increase the heuristic weight (however note that setting the heuristic weight to a value much lower than 1 will severely decrease performance).

Setting the heuristic scale (assuming that’s what you mean by heuristic weight) to a value of 3 gives me roughly what I’m looking for. It was set to 1, and setting it to 2 didn’t have much impact, but 3 makes them move in much straighter paths.

Does this make sense, and am I going to regret having it set to 3 for some reason?

Thank you.


Setting it to 3 might make it take suboptimal paths.
Generally if the heuristic scale is set to a value greater than 1, it cannot guarantee that the path will be optimal (i.e one of the shortest ones).
If your script is regularly recalculating path I wouldn’t worry too much about it though.

Thanks. Yeah, we don’t need to to be absolutely optimal. Just not making a bunch of zig zags.


What would be the easiest way to penalize additional turns? The animation in our game is such that the fewer turns a player makes, the better the animation looks.

Other than changing the heuristic, there is sadly no way of penalizing turns as that’s kinda incompatible with the pathfinding algorithm used.

1 Like