How to get an NPC following a player when the PLAYER looks at him?

(sorry for my horrible english)

Hi, i’m wondering if there’s something like the UDK node “Line of sight” in UE4 in blueprint.

5171-los.png

I want to get an npc following the player only when he’s looking at him, and i got it working in UDK, but after a week of research i can’t get it yet.

Thanks a lot for your help!

Use search, Enemy AI Line of Sight in Blueprints? - Programming & Scripting - Epic Developer Community Forums

Thanks for that, but i’m still a bit lost at it… Should i make a blueprint asset with every npc and add a pawnsensing component on it to get it reacting at player line of sight? I don’t know if i get how it works. I guess i’ll read the bp reference again.

You could check how AI is done in shooter game sample, it actually does not use pawn sensing component, but does use custom BTTask which calls LineOfSight eventually.

You can go that way too, but for more complex AI it’s better to use pawn sensing component, but pretty much it does not provide anything super cool, just some ready-to-use functionally, which anyway was not enough for me when i had to deal with it.

Regarding your question, you should have some base class for your NPCs, like MyNPC which is based on pawn, add pawn sensing component to MyNPC and then your NPC should be based on that class, which should have all the basic functionality for NPCs, and instances only change meshes and other stuff like that.

I gave some example of how to react to player being spotted, by default pawn sensing components checks for players only. And the last thing, you would use behavior tree for AI, there is a tutorial available somewhere on the forums, sorry don’t have link ATM.

Regards.

Ok now i know what’s wrong, i think i wrote wrong my question, i was asking for the player line of sight, i mean, the npc moves at you when the player is looking at him.

I knew how to move an npc when it spots the player, but not the inverse. I know is a strange question but i’m doing a special game.

So i tried adding sensing to “myCharacter”, but doesn’t work, or at least i can’t get it working.

Thanks a lot for your answers and sorry for my bad question!
At this rate I’ll have to add you in the credits x)

You still can add pawn sensing component to your player character/controller, just make sure to allow component to check for AI controllers, not sure how’s that bool called, something like “Sense Player Only”.

That is less complicated task at this point, you can simply check distance to the NPC and if it meets your needs call LineOfSight function to check if nothing blocks the view to the NPC.

Woha that’s it!!! The ■■■■ boolean! 9999 thanks mate !!!