can someone help me code something

i want to code it so that once a player looks at my custom enemy the custom enemy will freeze and once the player looks away the custom enemy will unfreeze but i have no idea how to do that. i already have the coding for a custom enemy set up and it works it follows the player and tries to kill the player but i want to add this feature. please help and thank you.

By looking, if you mean the player character’s face and not to camera that the player controls, you can cast a line trace from the player to somewhere further by using a “Line Trace by Channel” node. Plug in the player’s location into the start pin, then get the player’s forward vector, multiply it by a big number like 5000, add that onto the player’s location and plug the result into the end pin of the node. Get an “Is Valid?” node (with the question mark) and place it after your line trace node. Right click on the out hit pin of the node and split it, get the hit actor pin and connect it to the input object pin of the Is Valid node. After that node, place a “Branch” node. Get a “== (object)” node and connect it to the same hit actor pin by dragging out that hit actor pin and typing “==”, then select your enemy’s blueprint from the drop down menu as the other pin of the “== (object)” node. Once that’s done, plug that node’s red output pin into the condition pin of your Branch node. After it’s true pin, either stop the execution of your chasing task (how to do that completely depends on your implementation) or set your enemy’s max walk speed to 0 by using a Cast To node to cast to your enemy blueprint, getting it’s movement component, dragging a “Set Max Walk Speed” node and setting it to 0. And finally, do the opposite after the false pin of your Branch node, and you’ll be good to go :blush:

umm i dont really understand much of this do u think u could like record u doing it and send it to me. im new to uefn if u couldnt tell lol

Ummm… this is not the UEFN forum and someone told me that blueprints don’t exist in there :sweat_smile:

Hey @BamIsRich!

@VisAgilis has a great answer! I would change a few things though!

Line traces are literally 0 pixels wide so it would have to be center screen. A sphere or capsule trace would work better! Make sure to set the radius to a large one so it covers the screen.

Also, you can have it come out of the camera by getting reference to it on the player and having that location and forward be what is used. :slight_smile:

Hope that helps you!

Edit: Sorry, I posted this about the same time you mentioned UEFN. Let me change the category so people on the UEFN forum will see it! :slight_smile:

2 Likes

Its simple Use the Perception Trigger Device and attach it to the custom enemy. you can drive gameplay using line of sight between the device and players. When conditions related to line-of-sight checks are satisfied, the Perception Trigger transmits a signal through a event to activate other devices.

1 Like

could u show me how to do this please! i tried to figure out how to attach it the custom enemy but im using a zombie spawner that spawns in fiends just with a different model and im not sure how to make it attach once the custom models are spawned in. thanks

is the custom enemy a device or prop?

@Sonicegammer the blueprint is a building prop but it spawns in from a zombie spawner like once the player gets near it it spawns in and idk how to attach the perception device to that