# How can my NPCs open doors?

Hello,

I have npcs with an AIController with a behaviour tree and a mansion where they are walking in. Normally they stay inside their assigned room but when they are scared they should run to a savepoint which is located in the basement. Players can open and close doors. When the doors are open it is no problem and they find their way to the savepoint but when the door is closed they just run in the direction of the save point and get stuck on the wall.

I guess I could write my own navigation system where the NPCs can look up which door connects which rooms and than choose the shortest path but it would be easier if there is some way of getting the desired behaviour (NPCs opening doors) with the nav mesh that is provided by the engine.

Thanks in advance for any tipps on how to solve this

I don’t believe there is an really easy way with the navmesh. Maybe a Nav Link Proxy could help but as far as I read thus far it only allows you to jump off a ledge for example.

I didn’t watch those but maybe the first two of those video tutorials about AI contain what you need. At least it sounds like it:

Hm, i just think about saving the doors somewhere.
The Navigation mesh could be used for the movement inside a room.
You just need to have a way to save the rooms and the doors, so that
the NPC knows where he is.

It’s like a list that the NPC needs to go through.

Room 1 is the savepoint. He is in Room 5. So he has a list of Rooms
and doors. He knows that Room 5 has 2 doors, one to Room 3 and one
to Room 4. Room 3 has a door to Room 2 and this one a door to Room 1.

So now you need to think of a way to go through this list and give the
NPC the order to move to the Door. Opening it is the easy thing. Just make
a Collision Box or something that fires on colliding with the NPC and opens the door.
You can call a delay if the NPC leaves the door collider. This can close the door automaticaly.

The List would be an array of a struct. That struct has the RoomName and a second array of
door names/positions. If the NPC is in a room, you can have a collider here as well that
detects the NPC or maybe that the NPC detects the room and sets the current room
to the one hes in. So than he knows where he is and what doors are in the room.

It’s a bit complicated and i don’t know if there is an easier, more dynamical way.

Well using an approach with doors you could do something like ignoring the door in the navmesh or use a NavLinkProxy near the door to symbolize that there’s a way through. Open the door in its own blueprint and the standard pathfinding algorithm will do the rest.

Yep, like i said, i didn’t know that you can solve it dynamical. If there is something like a NavLinkProxy, than it will be easy for the OP.

Yes, NavLinkProxys are the way to go. Didnt know such a thing exists. Thanks!