I picked up some old A* pathfinding code I had in an old Unity project. Works pretty well, but paths generated that goes positive in the X or Z direction have this weird zig-zag thing to them.
Here’s an example of nice non-jaggy paths when I generate a path that goes negative in the X and Z axis:
###And here’s what I get when going positive:
Any idea what might be wrong? I.E, where to look? I’ll share some code soon.
Just guessing : for some reason your algorithm seems to “think” it’s shorter so …
=> maybe it’s a weight calculation problem ?
Hard coding 1 for vertical/horizontal moves and 1.4 for diagonal moves always worked for me.
EDIT : or maybe in those circumstances your algorithm is not considering the diagonal move.
Too me it looks like its only considering moves along one of the axes and not diagonal moves. Was the code originally written for a tile map? It looks like something I expect from navigating a tile map where there is a rule against diagonal moves.
Also, are you using the Euclidean or Manhattan heuristic – for tiles maps A* Manhattan is great, but it breaks down if you the distance guess are too big (too small is fine), and a Manhattan heuristic can do this if diagonals movement is allowed, so Euclidean should then be used.