Ai running into a wall when fleeing from player

The zigzagging probably happens because it’s calculating the location too often. You might be able to solve this particular issue with a cooldown decorator, so once you decide it should run 90° from it’s original direction, the cooldown has to pass before it changes back to original again. If it works how I think, it would of course still only reduce the zigzagging frequency, but might provide better results.

Making some more immersive running away / fleeing behavior is somewhat more complex I think.

I guess you should always try and work with navigable or even reachable points. It also highly depends on the number of obstructive objects and their density. I wouldn’t go with detecting the wall anyways, as your target location would potentially be way to close to the player. Maybe calculate a location 10m in the fleeing direction, then try and get a random reachable point in a close radius there. You could do this in a loop and increase the radius if you don’t find any points (the boolean output of the GetRandomReachablePointInRadius). If your radius reaches an upper limit, maybe because the AI reached the map border, it should choose some other way of finding a location, maybe try the same thing to forward-left / forward-right.

I am no specialist on this, that’s just how I’d try and make something like this.