How to get more straight paths? I'm getting too much Zigzag paths

Hi again :slight_smile:

I have a Grid Graph (Ray collider type) for a 2D game and movement is constrained to be inside a node/tile, not a free movement.

If I set Connections to Four, all paths are calculated perfectly around the tiles, but then I get mostly Zigzag paths, which is rather bad to see the entities navigating. In the image, the green is how most of the paths are returning and the yellow/red is the kind of path that I’d like to accomplish:

If I set Connections to Eight, I get mostly diagonal paths, which are fine and solve the Zigzag issue, but then entities move inside walls before reaching a close walkable tile. You can see the path line is too close to the obstacle, and then the entity sprite is drawn inside/above the obstacle before going to the free tile:

How to get the desired path of more straights/diagonals while not running inside obstacles?



You can try to adjust the heuristic. Go to Settings -> Heuristic and set it to Manhattan.

You can also try to disable “Cut Corners” in the grid graph settings. That will give you diagonal paths which do not move very close to obstacles.

Aaron, thanks again. I feel so embarrassed right now, because I tried every possible Heuristic before posting this, but I didn’t notice the “Cut Corners” setting.

Going with Eight Connections + Cut Corners did it.