How can I make my AI do an animation and do damage?

Hello, sorry if this is an easy question, but I am new to the server. I am making a sort of zombie game with AI enemies. I have managed that the AI senses me and runs towards me. But now I am having trouble with the animation and damage. I want the AI to do an animation when he’s standing next to me and do damage at the same time. This is my blueprint so far:

Thanks a lot already :slight_smile:

First is there any particular reason why you are looping back from Setting health to Cast to Character?

Second do you want the zombie to deal damage to the player at a certain point within an animation?

Because i want him to run after me again when the damage is done or isn’t this loop necessary? I’d prefer that the damage is done when the animation is over

I’m sure for what you are doing it wont be a huge deal, correct me if i’m wrong someone, unreal runs separate event calls on their own threads. stuff like that can be dangerous and cause infinite loops. Though OnSeenPawn gets called every Sensing Interval that a pawn is within it’s sight range. If you click on the PawnSensing component and look under AI there is a Sensing Interval thats how often it checks for see / hearing something. if you want it to happen more often then make that number smaller, just don’t do 0 because it will stop updating. This way you wont have to do that dangerous loop back.

Second it normally makes more sense to people to take damage when they see the animation actually impact the player rather than before or after, but if you want it to do it when the animation finishes then we can get that working no problem.

  • Since you are doing a move to, and waiting until success to attack, i suggest making the acceptable radius higher, otherwise the zombie will never make it to 100% right on top of the players location. Or you can turn on stop on overlap, that way as soon as they overlap it will finish success. I suggest using both.
  • Now for having the damage apply at the end of the animation, there is the more correct way, and there is the easier hack way lol, for now i’m going to suggest the hack way, unless you want to know the legit way of doing it.
  • after you call Play animation, do a delay for how ever long the animation is before deducting the health.
  • As a curious question, this is the zombie right? And you want to deal damage to the player, shouldn’t you be deducting the health from the player and not the zombie?
  • The way I explained for you to do it with the way you are already doing it is a hackish way of doing it. The proper way of doing all this would be to set up an Animation blueprint for your zombie where you use the animation graph to control what animations it’s playing and doing animation notifies to talk back with your zombie to tell him when to do thing.
  • For instance with a game i’m working on atm we have colliders attached to our enemies weapons that we use for detecting successful hits against the player. We turn on and off the colliders at specific points in the animation using animation notifies. this way the damage can only be applied while the attack animation is actually going and when the weapon is looks like it could be doing damage.
  • When we want an animation to play we tell the animation blueprint to play it rather than using the blueprint node play animation, it also allows us to blend between animations like running, attacking, and dieing, and also interupting animations for more important ones like death, so it doesn’t have to wait until an attack finishes before playing the death animation.
  • Don’t forget that if this works to make it as a solution. Also if you want me to go into more details on how to do this all the more legit way I can, but it is a lot of info.

O yea, so wait you are storing the players health on the zombie actor?

Thanks for your answer. Can you explain to what “the hack way” is? Yes it is a zombie. I have two kinds of health; currenthelath, which is from my firstperson character and aihealth which is for the zombie.

Thanks you! Oh so I didn’t have to create that looping? Yeah it is fine to do the damage after the animation ends. If you could help me with that, that would be awesome.

It is able to change that variable, but since you are not pulling a pin off from the character and then getting health, it looks like you are using the zombies health.

Oh I see. Thanks you. It would be great if you could go into more detail. It doesn’t have to be a difficult animation blueprint. Just run to the first peron character (which I have managed), then we he got to me attack (I have an animation for this) until I move again and then al over again. And then after he attacked me, that my health goes down. I have my players health set as a public variable. Or isn’t it able to change this variable in the event graph of the Ai character? Much thanks in advance!!