Support Forum

Grid Graph find path is zig zag?

Grid Graph
4 connections
Heuristic Manhattan
Heuristic Scale 3

ref:


That’s what I want,Make as few turns as possible。

ref:
https://arongranberg.com/astar/docs/pathfinding.html#Heuristic

That’s what I want,Make as few turns as possible。

Hi

There’s no way to find a path with a minimum number of turns. That would require a completely different pathfinding algorithm. However, the manhattan one should give you a pretty decent result on an axis aligned graph. Is your graph rotated perhaps?

Yes, it rotated by 45 degrees

Hmm, yeah, in that case the manhattan heuristic will not work as well for what you want.

Are there other heuristics we can look at? And if I want to change the algorithm, where should I change it to be more compliant?

The relevant part of the code is the Path.cs script -> CalculateHScore method. You probably want a manhattan heuristic, but rotated 45 degrees in the XZ plane so that it lines up with your graph.