Nudge AStarGrid2D to fewer turns and away from solid points

Godot Version

4.5

Question

How to nudge AStarGrid2D to favour paths with less turns/longer legs in the beginning and paths away from solid points?

From experimenting with the heuristics Manhatten has the most pleasing results most of the times. I do not allow diagonal movement.


	var astar = AStarGrid2D.new()
	astar.diagonal_mode = AStarGrid2D.DIAGONAL_MODE_NEVER
	astar.default_compute_heuristic = AStarGrid2D.HEURISTIC_MANHATTAN
	astar.default_estimate_heuristic = AStarGrid2D.HEURISTIC_MANHATTAN
	astar.update()
    

Obviously symmetrical paths can differ in turn positions. I would like less turns and later in the path (close to the destination). Some solutions are clingy to solid points (resulting in more turns than necessary). I assume I need a different heuristics for compute() and estimate().

Any ideas, hints?

I strongly recommend you look into NavigationAgent2D and NavigationRange2D. I literally implemented it in a new game today in about 15 minutes, and I can tweak all that stuff in the editor with sliders. It will take you longer than that to learn, but not much - and it will make your life so much easier.

Unless you enjoy playing with A*. In which case, enjoy!

I will have a look. I don’t have navigation layers or map just an abstract representation of a grid.