Can I block a path from a direction to prevent the path from turning around?

For my game, I can’t have the enemies be able to turn directly around, but sometimes the optimal path is to go back the way they came. I need a way to block a given direction from my pathfinding, so that the path instead is to go around, eg, “turn left three times and then turn right” or whatever. Is there a way to do this?

Fundamentally I could do this if I could just treat the enemy itself as an obstacle, but I can’t just put it on a layer that makes it an obstacle because then the path can’t calculate through other enemies. (I’d need to put each individual enemy on its own layer to pull that off.) Is there a way I can include one specific object/collider/arbitrary region as an obstacle for the pathfinding?


You may be interested in the ITraversalProvider: Utilities for turn-based games - A* Pathfinding Project