How do I kill an actor with a button press?

Hi guys,

I was wondering if anyone could help, I’ve been making a small stealth game. So far I have an Enemy AI who will chase, damage then kill the player over time. Although, my goal is to kill the NPC after hitting him in the back (pressing a button or mouse click). I seem to have run into abit of trouble here. My logic was - creating a collision box around the enemy, then once my player overlaps it, set a variable “In Hit Box” to true, then if player presses F, and “In Hit Box” is true, destroy the actor. This workflow isn’t really working - has anyone got any ideas what is wrong with my script or logic? I would really appreciate any help.

Many thanks,
Lou

You’re not referencing the player’s character at all. Try making a custom event in the AI’s character to destroy self and in the player’s character, blueprint the F trigger and cast it to the custom event. I had a similar problem, this will give you an idea of what I’m talking about:

use node “get AIController” then Cast to your enemy class and then destroyActor

Hey guys, thank you both for such a quick response.

I’m trying to get my head around the logic. I get that I have to cast to the enemy, although when I try and implement those two lines of script, I get warning errors such as the image. It feels like UE4 doesn’t recognise when I press F.

As well, dbzgod - that looks like a good solution, do you have any idea how I would put a key press somewhere in there too?

Hi there,

Thanks alot for the reply. When I implement this I get the errror “AI Character Chase” does not inherit from “AIController” (Cast to AI_CharacterChase would always fail) Do you have any more ideas of what I may be doing wrong?

When I implement this I get the errror “AI Character Chase” does not inherit from “AIController” (Cast to AI_CharacterChase would always fail) Do you have any more ideas of what I may be doing wrong?

if you have created an AI Controller and a AI Character for it, you must go to AI character blueprint and set AI controller .

88568-ai.png

set that to what you named your AI controller and then do that casting and see if it works

Thanks again for the reply, I implemented this - but I think it breaks the structure I currently have. It stops the AI from chasing me, because I’m using a custom "AI_Controller_Chase class. The button press does not work still. Should I be using this with a variable?

I cant seem to find a “Get AI_ControllerChase” -

Sorry for the confusion, I’m just getting alittle bit stuck at this part.

Hi dbzgod9,

Thanks alot for the help, I’ve had ago at this and got something that looks like this. I seem to be missing something big still - I cannot find my variable in my player character controller, so I’m unable to check to see if it’s true.

Would you be able to point me in the right direction again?

so plug return value of get AIController in object pin of Cast

Sorry - I did actually have that plugged in whilst I was trying it. I’m getting a warning message of Warning ‘AI Character Chase’ does not inherit from ‘AIController’ ( Cast To AI_CharacterChase would always fail).

I don’t know if you are using behavior tree, services or tasks but if have implemented an AI correctly and if it works when you play the game so killing and destroying it must not be such error prone.
why don’t you try watching a tutorial on AI. it can really help you.

this is what you need to begin with AIs →

and also this.

Thank you for your help saeedc, I’ve been using them alot to make my AI.

but i have an issue i dont see the ALcontroller as function dont know why. i want to create a blueprint when i press a key it kills an enemy but it feels im missing the AL controller thing