Make path with less turns

Is there any way how to make a path with less turns?
The red line is the path the best one for my game.

Too many unnecessary turns without obstacles looks weird.

I have sprite renders for 8 directions - it is important to have movement with 8 direction that means using squares(not raycast or funnel modifier) but with less turns. I would not like to increase node size because in that case I have wrong obstacles around buildings. To top of that it does not solve the issue completely.
Could you advise something in order to reduce turns amount? I tried Funnel Modifier and Raycast they look better in terms of turns, but they do not follow 8 directions movement pattern.

p.s. I use A* in ECS style that means call api directly.


You can adjust the A* Inspector → Settings → Heuristic setting.
See Documentation

Thanks for pointed out. Working flawlessly.

1 Like

Hi Aron.
Seems to me, I found a case when Heuristic does not work properly
This is my test with Manhattan and without:

I did not test DiagonalManhattan because according to documentation it does not make sense in 2d games.

As you can see I tried several values and there is no success.
And I am confused a bit. May be I missed something?
Because paths should not be such winding. It looks like it works a bit but not for all directions.


Manhattan, scale = 1.0 is what you probably should use. However, this is no guarantee that the path will have few turns, it’s merely a tendency. Using DiagonalManhattan would be better, but to use that in the XY plane you’d need to make one tiny change to the code.

You need to make the following changes to the Path.cs → CalculateHScore function:

Made those changes and result is the same as with manhattan.
Left manhattan with scale = 1.