How to make AI never turn backwards?

Trying to make an AI that moves a lot of like how the pac-man ghosts (only turning corners but never doing a 180). Anyone have a good idea of how to do this with A*?

Using a 2D gridgraph if that helps

Hi

You can start by setting the amount of connections from 8 to 4.
This will make it so that only the GraphNodes left right top and bottom are connected to the current GraphNode.

For movement it’s a bit different. If you’re using the AILerp movement script there should’t be any changes needed. For AIPath and RichAI you’ll want to modify the UpdateRotation funciton. And make it snap to the closest 90degree angle.

You might also want to change the A* Inspector -> Settings -> Heuristic to Manhattan. https://arongranberg.com/astar/docs/pathfinding.html#Heuristic

Hi

Preventing 180 degree turns is unfortunately not something you can enforce without some changes to the internal pathfinding algorithms. One possible “simple” solution would be to use an ITraversalProvider (see https://arongranberg.com/astar/docs/turnbased.html#ITraversalProvider) to make the node behind the ghost to appear to be unwalkable for it. Or optionally you could make it just have a really high penalty so that it could do an 180 degree turn if there was no other way.

1 Like

Awesome will check that out, love that you are so active on this forum, you’re a saint.

1 Like