How to make pathfinder avoid 360* angles and only go at 90* angles

How do I make it so that my pathfinding enemy has to take the long way around to the player by disallowing them from turning at anything but right angles, similar to the ghosts in pacman, but not in a maze, rather, in an open area. How might this be done?

This isn’t the most optimal way, but you could have an impassible object always behind it.

You can set the pathfinder to not use diagonals on the behavior setting tab for the object or use the diagonal movement action. They moved the checkbox inside the advanced section at the bottom of the object’s pathfinder behavior setup.

https://wiki.gdevelop.io/gdevelop5/behaviors/pathfinding/

Oh, yeah, I worded the title wrong, I think. The question I was asking wasn’t how to make the enemy go only at right angles, it was how to make it not go backward.

Maybe a maze / grid wouldn’t be so bad after all. Not in the pacman style, mind you, but a grid of squares all over, and all the squares are pathfinding obstacles. Then, there is a pathfinding obstacle behind them. The obstacle would have to be pathfinding toward a point that is constantly just far enough behind them to block the path behind them. This obstacle would have to be perfectly synchronized with the enemy. That way, it will always be in the way if the enemy tries to go back. This SHOULD work to the correct results.

That sounds fun but also challenging because of the limits/flaws of the pathfinder behavior. There is also a community pathfinding behavior called navmesh but it also has issues.

Both seem to have a problem with rotated obstacle objects. The builtin behavior will just go through rotated objects. If you create walls, it seems fine if you resize the wall object instead of rotating it. They use the bounding box not the hit box.

The navmesh seems to do the same albeit a little less. I haven’t used the navmesh much. I tested it just now and it seemed to occasionally take shortcuts through objects and for some reason it didn’t always take the shortest path.

I tested it with a single tall object in the center of the scene. When clicking on a destination near the top with the object near the otherside of the top, it would take the longer path down and back up instead of the shorter path over the top.

I’m just saying, do some testing of both of them before going down that path. Don’t rotate the walls and if you have a moving obstacle following the object don’t rotate it either. That part might be tough.

I’ve played with the concept of using doors as obstacles. It worked as long as the path gets updated since the path is a snapshot of the scene when the action to move the object is triggered.

Tips: Creating paths can be time consuming depending on the number of obstacles and the number of objects using the pathfinder. You can use a timer to update the path only occasionally. This can be tied to the distance to the destination. You can update more frequently when the distance is lower.

Both behaviors have a path found condition which can be inverted and used as a path not found. You can then repeat the path or trigger separate the object from the obstacle in case the object got stuck in an obstacle and can’t find a valid path.

Reducing the grid width, height can help with tight spaces.