x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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, Loualt text

Product Version: UE 4.10
Tags:
more ▼

asked Apr 26 '16 at 10:27 PM in Blueprint Scripting

avatar image

Lou345
6 1 2 4

avatar image Lou345 Apr 27 '16 at 12:03 AM

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? alt text

warnings.png (38.2 kB)
avatar image Lou345 Apr 27 '16 at 12:10 AM

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?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

3 answers: sort voted first

use node "get AIController" then Cast to your enemy class and then destroyActor alt text

1.png (56.3 kB)
more ▼

answered Apr 26 '16 at 11:38 PM

avatar image

saeedc
2.4k 72 41 105

avatar image Lou345 Apr 27 '16 at 12:09 AM

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?

avatar image saeedc Apr 27 '16 at 09:10 AM

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

ai.png (15.4 kB)
avatar image saeedc Apr 27 '16 at 09:14 AM

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

avatar image Lou345 Apr 27 '16 at 09:32 AM

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.alt text

ai_chase.png (57.6 kB)
avatar image saeedc Apr 27 '16 at 03:57 PM

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

avatar image Lou345 Apr 27 '16 at 04:06 PM

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).

avatar image saeedc Apr 27 '16 at 04:33 PM

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.

avatar image saeedc Apr 27 '16 at 04:35 PM

this is what you need to begin with AIs -> link text

avatar image saeedc Apr 27 '16 at 04:38 PM

and also this. link text

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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:

https://forums.unrealengine.com/showthread.php?108060-AttachActorToComponent-not-working

more ▼

answered Apr 26 '16 at 11:25 PM

avatar image

dbzgod9
1 1 3

avatar image Lou345 Apr 27 '16 at 01:42 PM

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?alt text

aihelp.png (132.3 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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

more ▼

answered Apr 28 '16 at 07:52 PM

avatar image

Lou345
6 1 2 4

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question