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

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!!!

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.

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.

Are you applying any damage with the line trace hit?

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:

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?

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

82742-anydamage.png

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!

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

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.

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.

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

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

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:

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.

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!

Awesome! Thank you so much!

Here ya go try this:

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!