How to make NPCs open doors?

Hi, I’m making a game based on NPCs. And I can’t figure out how to make NPCs open and close doors. I need the NPC to open doors using the following algorithm: unlock door > open door > go inside > close door > lock door. I tried doing this using waypoint labels, moving the PathFinding route so it places two waypoints on the door and runs the algorithm. But it didn’t help. And now I don’t know any other ways to do this. Can anyone please help?

3 Likes

could you provide (a part) of your code?

1 Like

It seems to me that this code with waypoint labels is impossible to read, so I’m only asking for ways to make this system not rely on waypoint labels because it has a lot of bugs. But I can say that I used NoobPath module for this.

1 Like

I’m pretty sure there’s a cleaner way to do it but for my system I just added a pathfinding modifier to the door and made the door script open itself when an npc is close enough.

I would just make the door open if there’s an npc and lock it for players (kinda simulates the npc locking and unlocking)

If you have animations for locking and unlocking, you could stop the npc when it’s close enough, play the animation, then move the npc other side, lock it and recalculate a path to the end position.

Sorry for the bad wording, English isn’t my native language.

2 Likes

You could have 2 invisible parts on each side of the door then pathfind to one point, MoveTo() to the other, then continue your pathfinding. This way, you’re not modifying the pathfinding, but instead splitting it up to avoid any advanced work.

2 Likes

did you do this using the touched function or magnitude?

i think you can just make the door trigger the unlock animation then the open animation and so on and if you wanna move your npc then use the MoveTo() from the humanoid

3 Likes

Oh! You might be able to use Pathfinding Links for this! Make sure to check this out! With pathfinding links you can accurately check when an NPC tries to do something! Like for example if an NPC wants to go past a wall and the only way to go through is a door. If you wanna pathfind to the other side it will error, but if you use a pathfinding link it will use that to go through!

you need your npcs to have a topological map of the environment - so that they know beforehand which door needs to be reached in order to go into a given chamber, and in which sequence
then they begin traversing the selected path
reach door, play unlocking animation, unlock, play opening animation, open, go through door, play closing, play locking, continue path
notice you can make doors and npcs themselves to be on mutually exclusive collision groups - but only to enable usage of Pathfinding Links; the logic stays the same anyways

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.