Download

Easy ways to inform NPC of player's state?

Hi all,

I’m looking for a clean and easy method(s) for informing AI chars of player state. For example, I want enemy AI to lose sight of the player when I activate adaptive camouflage (a la Predator cloak, think Crysis). I know I can toggle a boolean variable on my player, but how do I transmit that info to the AI so that they know to stop seeing my player, i.e they pretend he’s not there.

I thought of some methods, but they seem to be too complicated than what I’m looking for.

For instance, I can create a game rule that informs all NPCs that the player is cloaked and they lose sight.
Another idea was to make individual AI check if player’s “cloaked” boolean is checked, but that would have to be checked every frame(and I fear it’s expensive)

Please if anyone has any method they like to share, I would greatly appreciate it.

P.S. I wonder if there’s something packaged with UE4. I know UDK had a boolean “isPlayerVisible”(?) or something like that.

Thank you.

Bump.

Hi, I’d really like to know of any methods.

Thank you.

Hello,
At least, you can set a bool in your character when camouflage is on (or an integer if you have different states : run, walk, crouch, hidden) and when an enemy detects the character, bool is checked. If cloak active, then ignore, if not then start event. With integer you can modulate with range and eye / ear detection.

Checking a boolean every frame is perhaps less than optimal but hardly expensive. I think you can go that way. Another thing you could consider is letting NPCs listen to cloak events:

  • Let your player pawn have a list of NPC references (for example name it CloakListeners)
  • NPCs that target the player register themselves (add themselves to the CloakListeners list)
  • When the player pawn cloaks, the player pawn calls a function on all registered NPCs so that NPCs that are currently targeting the player drop their target
  • Be sure to unregister NPCs when they are no longer interested in cloak events (like when they are removed from play)!

Can you tell or show a bit of how you are doing your AI, specifically how do you select a target? For example, do your NPCs just grab a reference to the player pawn using the BP node Get Player Pawn, or do they actually look for the player?

If you’re doing traces (line traces, sphere traces) or volumes (OnBeginActorOverlap) to detect the player, how about setting the player pawn to ignore the Visibility channel while cloaked? I.e. your pawn never shows up in visibility results, sounds like a intuitive solution to cloaking? :slight_smile: