# Can I get an AI character to activate when I hit it with a line trace?

**URL:** <https://forums.unrealengine.com/t/can-i-get-an-ai-character-to-activate-when-i-hit-it-with-a-line-trace/351289>\
**Category:** AI\
**Tags:** ai-navigation, unreal-engine, UE4, Blueprint, question\
**Created:** [March 21, 2016, 9:58pm UTC](https://forums.unrealengine.com/t/can-i-get-an-ai-character-to-activate-when-i-hit-it-with-a-line-trace/351289 "2016-03-21T21:58:46Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anaklosmos](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Anaklosmos](https://forums.unrealengine.com/u/Anaklosmos)\
**Post date:** [March 21, 2016, 9:58pm UTC](https://forums.unrealengine.com/t/can-i-get-an-ai-character-to-activate-when-i-hit-it-with-a-line-trace/351289/1 "2016-03-21T21:58:46Z")

</div>

Hey guys! As of now, I have a blueprint set up for the AI to follow me when I get in his field of view and he will stop following me when I leave his field of view. I am trying to “Shoot” a line trace at a zombie AI that I have set up, and I want him to begin following me after I shoot him but stop following me after I leave his field of view.

Ex. I walk up behind the zombie and shoot him and he will turn around and chase me until I leave his field of view.

I had set up an event dispatcher off of my line trace and it was making the zombie follow me after I shot it, however, because the zombie was set to simply follow me after that event, rather than when he saw me, he would not stop following me after I left his field of view. Is there a way to get this to work? Perhaps via the “heard noise” attribute of the AI? Or another way? Thanks a lot!!!

---

<div class="post-metadata">

**Author:** ![Black\_Phoenyx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Black\_Phoenyx](https://forums.unrealengine.com/u/Black_Phoenyx)\
**Post date:** [March 21, 2016, 10:13pm UTC](https://forums.unrealengine.com/t/can-i-get-an-ai-character-to-activate-when-i-hit-it-with-a-line-trace/351289/2 "2016-03-21T22:13:49Z")

</div>

Have you tried adding the same logic that handles his loss of sight/forget about you that you are using already and adding the same to the one that handles when he gets shot? The way you make him stop following you with the sight can also be used to make him stop when you shoot him.

---

<div class="post-metadata">

**Author:** ![Anaklosmos](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Anaklosmos](https://forums.unrealengine.com/u/Anaklosmos)\
**Post date:** [March 25, 2016, 10:54pm UTC](https://forums.unrealengine.com/t/can-i-get-an-ai-character-to-activate-when-i-hit-it-with-a-line-trace/351289/3 "2016-03-25T22:54:13Z")

</div>

As of now I have him run towards the player after the player falls within the AI pawn-sensing field of view. This is shown below in my screenshot. These are the only nodes in my AI character. This means that there is no actual “stop following” logic. I have tried making a variable that would control this stopping, however I couldn’t get it to work.

 ![83887-zom.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/6/8/368c5d81059ffc4cb9e67fcb5cd2a25e24853a12.png)

---

<div class="post-metadata">

**Author:** ![Black\_Phoenyx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Black\_Phoenyx](https://forums.unrealengine.com/u/Black_Phoenyx)\
**Post date:** [March 25, 2016, 11:16pm UTC](https://forums.unrealengine.com/t/can-i-get-an-ai-character-to-activate-when-i-hit-it-with-a-line-trace/351289/4 "2016-03-25T23:16:11Z")

</div>

Are you applying any damage with the line trace hit?

---

<div class="post-metadata">

**Author:** ![Black\_Phoenyx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Black\_Phoenyx](https://forums.unrealengine.com/u/Black_Phoenyx)\
**Post date:** [March 25, 2016, 11:33pm UTC](https://forums.unrealengine.com/t/can-i-get-an-ai-character-to-activate-when-i-hit-it-with-a-line-trace/351289/5 "2016-03-25T23:33:53Z")

</div>

Try a Set Focus Node and a Clear Focus…this makes the AI look at you and allows for the Pawn Sensing to take over once you clear the focus. But you will need to setup a damage event on the trace hit or you could use another way to call it this is just an example:

 ![83890-setfocusondamage.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/7/3/b73cde7786ecd62017370e4a3f4b6aa5d2c268fe.png)

---

<div class="post-metadata">

**Author:** ![Anaklosmos](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Anaklosmos](https://forums.unrealengine.com/u/Anaklosmos)\
**Post date:** [March 26, 2016, 3:20pm UTC](https://forums.unrealengine.com/t/can-i-get-an-ai-character-to-activate-when-i-hit-it-with-a-line-trace/351289/6 "2016-03-26T15:20:22Z")

</div>

I really am not sure how to use the damage system in Unreal, so I did a workaround. Here is what I have done to handle that. Would there be a way for me to use the damage system to get the same effect as what I have done here?

 ![83930-damage.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/2/b/32bbeee801fa07976e59579dcf3eb1c66f40dbd4.png)

---

<div class="post-metadata">

**Author:** ![Black\_Phoenyx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Black\_Phoenyx](https://forums.unrealengine.com/u/Black_Phoenyx)\
**Post date:** [March 26, 2016, 3:27pm UTC](https://forums.unrealengine.com/t/can-i-get-an-ai-character-to-activate-when-i-hit-it-with-a-line-trace/351289/7 "2016-03-26T15:27:57Z")

</div>

Yes and it is much easier to setup…in your AI character BP add this:

![82742-anydamage.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/e/e/4ee8b4284e613a05f0cf491ddc3e6280c3d9a76d.png)

---

<div class="post-metadata">

**Author:** ![Anaklosmos](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Anaklosmos](https://forums.unrealengine.com/u/Anaklosmos)\
**Post date:** [March 26, 2016, 7:25pm UTC](https://forums.unrealengine.com/t/can-i-get-an-ai-character-to-activate-when-i-hit-it-with-a-line-trace/351289/8 "2016-03-26T19:25:56Z")

</div>

Okay, I have attached my player blueprint and my AI blueprint below. The damage is working flawlessly, thank you very much! However, the focus doesn’t seem to be working correctly? Would there simply be a way to make the zombie turn in the direction that I have shot him from so he could see me? Is that what we are trying to do?

PS… Ignore the cast to player from my AI, it is simply there to show the damage that I have dealt temporarily. Also, I really wanted to thank you so much for the fast replies! You’re really helping out a lot!

 ![83966-char.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/8/a/38a6bee68a394c880bcc8f5ccbe4c7b4a31976b3.png)

 ![83967-zom.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/9/e/09e619957af1639bf4ca9bfc69310e59f41ad999.png)

---

<div class="post-metadata">

**Author:** ![Black\_Phoenyx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Black\_Phoenyx](https://forums.unrealengine.com/u/Black_Phoenyx)\
**Post date:** [March 26, 2016, 8:03pm UTC](https://forums.unrealengine.com/t/can-i-get-an-ai-character-to-activate-when-i-hit-it-with-a-line-trace/351289/9 "2016-03-26T20:03:39Z")

</div>

Is the Set Focus firing? Add a print string at the end so we can tell if it is firing. It should turn to face the player if focus is firing correctly

---

<div class="post-metadata">

**Author:** ![Anaklosmos](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Anaklosmos](https://forums.unrealengine.com/u/Anaklosmos)\
**Post date:** [March 27, 2016, 6:52pm UTC](https://forums.unrealengine.com/t/can-i-get-an-ai-character-to-activate-when-i-hit-it-with-a-line-trace/351289/10 "2016-03-27T18:52:34Z")

</div>

Yes it is firing, but the AI is still not turning to face me. Do I need to have a different node plugged into the instigator? I have tried plugging a “Get player controller” straight into the “set focus” and they still didn’t turn.

---

<div class="post-metadata">

**Author:** ![Black\_Phoenyx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Black\_Phoenyx](https://forums.unrealengine.com/u/Black_Phoenyx)\
**Post date:** [March 28, 2016, 3:01pm UTC](https://forums.unrealengine.com/t/can-i-get-an-ai-character-to-activate-when-i-hit-it-with-a-line-trace/351289/11 "2016-03-28T15:01:11Z")

</div>

Ok, are you setting the instigator when you apply damage? We need to see what it is getting as the instigator, drag the pin from instigator and plug it into a print string right after the any damage event to see what it is showing.

---

<div class="post-metadata">

**Author:** ![Anaklosmos](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Anaklosmos](https://forums.unrealengine.com/u/Anaklosmos)\
**Post date:** [March 28, 2016, 4:43pm UTC](https://forums.unrealengine.com/t/can-i-get-an-ai-character-to-activate-when-i-hit-it-with-a-line-trace/351289/12 "2016-03-28T16:43:34Z")

</div>

When I shoot the AI, it is returning “Player controller”. This is what we wanted correct?

---

<div class="post-metadata">

**Author:** ![Black\_Phoenyx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Black\_Phoenyx](https://forums.unrealengine.com/u/Black_Phoenyx)\
**Post date:** [March 28, 2016, 5:24pm UTC](https://forums.unrealengine.com/t/can-i-get-an-ai-character-to-activate-when-i-hit-it-with-a-line-trace/351289/13 "2016-03-28T17:24:28Z")

</div>

Does it have a number with the controller as well? Yeah we want a controller but we need to make sure that it is your player character’s controller and not just a generic controller return value

---

<div class="post-metadata">

**Author:** ![Black\_Phoenyx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Black\_Phoenyx](https://forums.unrealengine.com/u/Black_Phoenyx)\
**Post date:** [March 28, 2016, 5:30pm UTC](https://forums.unrealengine.com/t/can-i-get-an-ai-character-to-activate-when-i-hit-it-with-a-line-trace/351289/14 "2016-03-28T17:30:18Z")

</div>

We may just want to hard code a turn around if the focus doesn’t work right for you. Test this and let me know if it works for you when you damage the AI:

 ![84141-bypassfocus.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/c/8/7c876ecd2a004c76c8f87ed44d42496adf5b4dc6.png)

---

<div class="post-metadata">

**Author:** ![Anaklosmos](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Anaklosmos](https://forums.unrealengine.com/u/Anaklosmos)\
**Post date:** [March 29, 2016, 3:33am UTC](https://forums.unrealengine.com/t/can-i-get-an-ai-character-to-activate-when-i-hit-it-with-a-line-trace/351289/15 "2016-03-29T03:33:43Z")

</div>

Okay this works great! The AI are turning to look at me and everything is working as it should! I may be being a little picky, but it looks strange that they simply are set to a new rotation… while we are here, would there be a way to make them actually spin around rather than simply setting their rotation to look straight at me? If not, this will work just fine! Thank you so much for all of the great advice! I really appreciate it!

---

<div class="post-metadata">

**Author:** ![Black\_Phoenyx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Black\_Phoenyx](https://forums.unrealengine.com/u/Black_Phoenyx)\
**Post date:** [March 29, 2016, 3:37am UTC](https://forums.unrealengine.com/t/can-i-get-an-ai-character-to-activate-when-i-hit-it-with-a-line-trace/351289/16 "2016-03-29T03:37:51Z")

</div>

Yeah you can use an rinterpto node to interpolate from their current Rot to the target Rot…im away from the desk right now otherwise I’d post a screenshot of the setup…i will post one when I get back to the office in the morning.

---

<div class="post-metadata">

**Author:** ![Anaklosmos](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Anaklosmos](https://forums.unrealengine.com/u/Anaklosmos)\
**Post date:** [March 29, 2016, 3:46am UTC](https://forums.unrealengine.com/t/can-i-get-an-ai-character-to-activate-when-i-hit-it-with-a-line-trace/351289/17 "2016-03-29T03:46:23Z")

</div>

Awesome! Thank you so much!

---

<div class="post-metadata">

**Author:** ![Black\_Phoenyx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Black\_Phoenyx](https://forums.unrealengine.com/u/Black_Phoenyx)\
**Post date:** [March 29, 2016, 2:09pm UTC](https://forums.unrealengine.com/t/can-i-get-an-ai-character-to-activate-when-i-hit-it-with-a-line-trace/351289/18 "2016-03-29T14:09:26Z")

</div>

Here ya go try this:

 ![84230-zombierinterptoplayer.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/5/c/f5c1fc78ddd4185746cebbabf8bb4cf0f5c146f9.png)

---

<div class="post-metadata">

**Author:** ![Anaklosmos](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Anaklosmos](https://forums.unrealengine.com/u/Anaklosmos)\
**Post date:** [March 30, 2016, 4:33am UTC](https://forums.unrealengine.com/t/can-i-get-an-ai-character-to-activate-when-i-hit-it-with-a-line-trace/351289/19 "2016-03-30T04:33:45Z")

</div>

This is working great! I have also set up a noise maker node so the zombies will react when I shoot near them. Thanks so much for all of the help. I really appreciate it!
