NPC Fleeing with Unity Pathfinding?

What is the best way to make enemies flee from your character. I need to create almost an impulse where the player causes the enemies to run away from him in all directions. I have tried a few things, one of which was additivly altering their destination but this didnt really have the effect i wanted.

Any tips, maths or links to information is appreciated.

Kind Regards


Pathfinding and fleeing in terror usually don’t mix. Fleeing might be running down a hallway and turning into a dead-end. Even if you know about the dead-end, still an OK place to hide (and you might forget in your panic.) Pathfinding will never have you run into a dead-end.

With pathfinding, you first pick a spot. Suppose you pick just past the end of the hallway. The pathfinder figures out you have to run crosswise to the scary thing in order to get to there. It ends up looking more like “everyone and calmly follow the exit signs” Using pathfinding + avoidance will probably prevent you from “fleeing” towards an enemy standing in the only doorway out of a room, but it can’t help you know what to do in that situation, or where to try to flee to in the first place.

Simplest trick is to do a few quick ray casts “away” from the scary thing, and run whichever one has the most room.