Just finished the new escape system I wrote about (here) and everything seems to be working so far.
With standard game pathfinding, you pick an NPC and tell it where to go. It then calculates the shortest path to get there and follows it. This works fine in most cases: make a noise, the npc goes toward the noise to investigate; a cop sees you, walks towards your position and shoots, etc.
Designing a system where NPCs flee from you is a bit more complicated. People being afraid of you is kind of the whole point to a game like this. If they see you they should run away, towards an exit or hide. However, because standard pathfinding calculates the shortest path to a point, if you’re standing in that path, instead of running away from you, the NPC with run towards you to get to the exit. This breaks the game.
I won’t go into the old system I had set up (you can try it in Halloween Beta 3.2) but it had a major problems scaling to larger levels and didn’t work in the more linear areas. So I came up with something new.
The game takes the node that the player is standing closest to and switches it off. The nodes surrounding the player are taxed and picked last, so the NPC won’t run by the player unless there is no other way.
The npc then calculates a path to each exit point (up to 2 per level) and picks the shortest one. Each time the NPC reaches a new node on that path, it draws a new path. Because the player is always moving, the NPC needs to take the player’s new position into account at every node.
If the player is spotted, the NPC spins around in the opposite direction, screams, and draws a new path. If they ever get cornered, they give up and surrender.
The good news is that the debugging to make all of that work is probably the biggest pain the the ass I had left for completing the game.