r/howdidtheycodeit • u/King_Bonio • Jun 27 '22
Question How did they code pathfinding for Mr X in Resident Evil 2 Remake, considering closed doors
I'm quite new to pathfinding and I've heard doors are a complete nightmare, especially if they're closed.
How did they manage to have normal mobs unable to move through closed doors but allow Mr X to see through closed doors, open them and go through them?
22
Upvotes
16
u/prog_meister Jun 27 '22
There are a few different methods of pathfinding. Let's assume it's something like A* where you have a grid of nodes in the level. The nodes tell the pathfinding agent whether that particular point in space is walkable or not. The agent then calculates a path between the nodes until it finds the destination node.
So when the pathfinding algorithm encounters a node marked as a door, it can check if it's a zombie or if it's Mr X who is searching for a path. If it's a zombie, it's unwalkable. If it's Mr X, it's walkable.
For opening the door, he will need to detect it. Once he has a path, which is a list of nodes that he moves between, all he needs to do is check if the next node in the path is a door node. Then instead of doing his normal walk animation, he does a door opening animation.
5
u/beautifulgirl789 Jun 27 '22
Just a sidenote: doors are a godsend to a good pathfinding algorithm. Pathfinders can struggle when there are too many viable paths (too many nodes to traverse = lots of time spent). Having doors enable many optimizations, such as being able to treat entire rooms as single nodes with each door as a connector.