Forum rules - please read before posting.

How to detect if a stationary NPC is inside a Trigger?

edited February 18 in Technical Q&A

I'm trying to figure out the best way to detect whether a NPC (one that never walks) is inside a trigger zone or not. (Sometimes that NPC will be teleport to other rooms so handling his position with variables would be more complicated.)
The setup: The player needs to pick up an object from a room, but only if the NPC is not in that room. I want to use a trigger placed inside the room to determine the NPC's presence.

What I understand so far: I know the logic I want to implement — I just need to set a variable based on whether the NPC is inside the trigger or not, and then check that variable before allowing the pickup action.

My question: Since the NPC doesn't walk, I can't rely on OnEnter/OnExit events firing during gameplay. I need to actively check the NPC's state at the moment the player tries to interact with the object.

I guess I need to use the action Object->Send Message to the trigger->Interact... BUT... should I use two separate trigger components — one for "NPC inside" and one for "NPC outside" — and call each independently?
Is there a cleaner way to handle this with a single trigger?

Any guidance would be greatly appreciated!

Comments

  • edited February 19

    Is this to say the Trigger spans the entire room, such that the position within the room is irrelevant?

    A Trigger that covers the whole scene will detect an object that spawns inside it. You don't need to manually interact with it, but adding a second AC_Trigger component to the same Trigger will allow you to have an Enter/Exit pairing that both use the same Collider. Add a Variables component to the same object, define a Bool, and you can then set that Bool to True in OnEnter, and False in OnExit.

    The other way to approach this - given your NPC moves between scenes - would be to enable Player-switching, and make the NPC an inactive Player. Inactive Players can be moved between scenes using the Player: Teleport inactive Action, and AC will handle their spawning automatically. Checking if they're in the current scene is then just a case of using the Scene: Check Action which - if player-switching is enabled - can be used to check if an inactive Player is in a given scene.

  • edited February 19

    Ok, I've been doing several tests and I can make it work with OnEnter, but OnExit doesn't work. I switched to detect my player just in case there was some issue with the NPC, but I get the same result. The trigger detects when the Player enters it, but not when they exit.
    The interesting part is that both work if I walk outside the trigger. But when I teleport the player, only OnEnter is triggered.

    EDIT: Found the solution. I switched the detection mode to Transform Position instead of RigidBody Collision. The only small issue is that it seems I cannot inject the object to detect through a parameter, right?

  • You can't set what objects the Trigger can detect through parameters, but you can assign the detected object to a GameObject parameter, and then use the ActionList: Check parameter Action to compare its value with another one.

  • Got it. Thanks

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.