A* pathfinding how to prefer a nicer path

Here is the path my A* always finds.

It is really annoying, because this path would be much nicer for the player. The problem is I have no idea how to change it, nor I even can think of how to google this up… I tried few keywords, but with no results.

Thanks for helping! :smiley:

Why would the bottom path be nicer for the player? Without knowing that I cannot give any sensible suggestion.

Imagine that yellow square is where you actually stop, not on green tiles, and you move on from yellow square on wards.
This is what I get with my A* pathfinding. It kinda looks choppy when you go to the nearest tile like that over and over again.

Here is how it should look. I think you understand what I mean…

Ah thats a bit more clear. Looks a bit weird, like it sends you to the bottom-left of each tile instead of the center. Do you have any code to check out?

You need to increase the cost of moving diagonally then your paths will prefer straight lines and move diagonally only when necessary.

In this case it doesn’t matter for my code which path to pick. They both have the same movement cost. I will try to implement something like that if first move is diagonal, its cost will be lower than vertical/horizontal.

It looks like you can simply change A-B pathfinging to B-A and reverse the path.