Download

On key press for AI death

Hey guys,

I’m building a little project, but I’ve managed to get myself abit stuck - I’m sure the answer is pretty simple, I’m just abit new to the engine still. Basically, I have built a game of patrolling AI, and once they find the player they chase him, take away health and eventually kill him. This bit is all working fine, but my issue is with killing the AI.

I’ve set a hitbox behind the enemy AI, and once the player is inside their hitbox, he should be able to press “F” and destroy them. I’ve tried quite a few different ways. My logic at the moment is, Once the player hits the collision box, set the variable “InHitBox” to true, then the palyer can press “F” check the variable is true, then if so -destroy the actor. I feel like I’m missing something simple, or have I made abit of an oversight? I’ve tried casting to the player and also trying to find a on button press fuction which isn’t an event but I’m not having much luck.

Any help big or small would really be appreciated.

Thanks for all the fish.
Lou

your AI is not controlled by your Controller so there cant be a button event
try this: on overlap store a reference of your AI inside of your char. then on button press (inside your char) take the reference variable and destroy it.
inside of the AI you have start overlap and end overlap. if it starts grab the other actor, cast to your char, grab the nod and make “set nameofyourvariable” -> self.
on end overlap you clear the AI reference variable.

Hi,

Thank you alot for the answer - it is starting to make sense. I seem to have trouble referencing the variable “InHitBox” inside of my character. Am I doing something wrong? Here are the nodes I’ve used so far, it doesn’t work because I’m missing that main component I think. Would you be able to point me in the right direction again? I can’t cast to my InHitBox variable to my third person character.
a17725d12d82f5c5848c19056a3bf932d7dad383.png

instead of the bool use a variable that is from type third person character and plug the cast into it. on end overlap you set the variable to nothing so it clears. on F press you take the variable and destroy it. if this isn’t clear enough I can show you how its done in estimated 3-4 hours when im home

Thank you again, I’m trying to do that now - but I keep getting errors, I will continue to play around with it for a few hours. Although I think it would be really useful if you could show me the logic when you get home .

Cheers,

ok here are some screens
f21718b3d1a76d521f6b1f03326ad446b5c7b1b1.png
first you create a variable inside of your char. its type should be your AI bp as reference. i dont have any AI so i put in char just to demonstrate

next do this inside of your AI
because of the cast you can access the variable of your char. and your char has an empty AI variable which you fill with your AI now
b8e0d2afe9b5211e91f1f6072adbac18.png

last step is your F button inside of your char
now the variable is filled with your AI (only when you overlap otherwise you unfill it on end overlap). you can now directly access it and destroy it
32165000c22d71252529cdababb60062.png

give me a quick feedback whether that worked for you :slight_smile:

Thank you so much! That worked like a treat!!!

Sorry, I was having an issue with it before - it all makes sense now. I really appreciate your help. :slight_smile:

no problem :slight_smile: have a nice day

I don’t want to push my luck, but I was just wondering if you may know what the other issue is with my scene. I have AI characters walking around, and they attack me and kill me which is fine. But when they group up and attack me at the same time, they cannot retrieve the same “health” float at the same time ( I think) , so my game starts erroring although I still lose health. Would you know of any way on how to fix this? I know this is a serperate issue - I’ll make another forum post, I was just wondering if you may have any ideas. Thank you again.
Error1.png559f3c7903a0e521d468bfcda8d1eebf6136dac2.png

either the reference is lost and he cant further execute the code or your char is already dead and he cant access the health. try to make a “is valid” after the cast and plug in the blue wire. if its valid execute the code as usual. if its not valid, leave it empty

ah and plug the upper compare float with the 1 sec delay into the “is valid”, so he checks if its valid every loop

Hi MajekPL,

Thanks again for spending the time to have alook at my project. I’ve done what you have suggested as it works alot better now, it does seem to stop taking health away randomly which is slightly confusing - I’ve made a quick video to help show the issue, I keep getting errors which is slightly worrying too. I think it is because both characters are trying to reduce the float at the same time or the reference is getting lost?

[video]https://youtu.be/bx6neNqaBDI[/video]

IMprovedBlueprints.png
Errors2.png

try to store the character reference variable from the cast as you did before. that’s everything that should be on start overlap.
then you do this steps.

  1. create a new event and call it what ever you want.
  2. put all your other code into it, but without the delay. and instead of the cast you plug in the actual character reference variable.
  3. make a “Timer by event” and connect the red box of your event to it. set it to loop and give it the value you had on your delay before.

now on overlap he stores the char and starts a timer that execute the event that gives the damage once in a given time.

hint: instead of compare you can just use a branch. for this drag a wire from your health wire and write < with this you can compare whether its smaller 0. if yes it gives a true. plug it into the branch.

what is this “quit” thing on the end? maybe he tries to apply damage after the player already quitted and that’s why he is giving failures.
the failures basically tells you that the cast reference is no longer available. that can be because youre looping here without storing the variable or because the char is not accessable anymore because reasons. what happens inside of your char if he goes below 0 health?