How to minimize directional changes?

Hi. I am a beginner to Unity and C#, and am making a real-time RPG where characters move by clicking somewhere on the screen.

I have been successful in getting the A* project to work, thanks to this tutorial: http://hobblygobbly.tumblr.com/post/93960257057/how-to-setup-the-a-pathfinding-project-in-a-2d

My characters are finding the optimal path, restricted to 8 directions, while moving through 16x16 nodes. The problem, however, is that the paths are often generated in a way such that there are way too many directional changes. This causes the character’s sprite to rapidly spasm between two adjacent directions. Here is an example of one such path: http://imgur.com/a/OAE8c

My solution was to perhaps change the algorithm so that it calculates P_min+T_min instead of P_min, where P_min is the minimum distance from the start to end nodes, while T_min is the least number of turns. This would eliminate the unnecessarily large number of turns. I’m not sure how I would implement that though. Can someone help me?

I haven’t touched any of the code from the download link, and am using the Free Version 4.0.10.

Any help would be appreciated!

Hi

Try to change the ‘Heuristic’ setting in A* Inspector -> Settings -> Pathfinding.
Try to set it to Diagonal Manhattan or Manhattan. I think that should give you a better path.

That’s a lot better. Thank you!