How to make an NPC perceive the player character's perception?

I’m learning how to make AI enemies but I can’t figure this out:

I want to make an NPC that just repeats an idle animation until it has perceived that the player character has perceived it. I want this NPC to not move on from this task until it perceives you perceiving it, like the Witch from L4D. When you look away, the health variable is going to slowly regenerate.

I’ve got a trace coming from the FPS camera of the player character that’s working on other objects, I’ve attached a copy of that BP. Every trace that goes from the player character is going to reduce the health variable in the NPC, and when it reaches zero I want it to go to the next stage of the behavior tree. I could probably put this in the NPC blueprint but I think it’d probably be best to do it in the Behavior Tree; this also doesn’t take into account the NPC’s perception.

Hey @fartificial!

So this is where DOT products come in handy.

You use GetForward on both the player and NPC and plug them into the Vertex inputs, and the return will be from -1 to 1.

1= the two are facing each other perfectly
0= they are perfectly perpendicular
-1= they are facing exactly opposite

So you can use this, if you get a positive .5 or higher that means the enemy would be in the player’s view and vice versa!

Unless you wanted it to trigger regardless of the enemy’s perception?

1 Like

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