(Solved) How To Trigger AI Melee Attack Animation?

just play the Montage when u Deal Damage when Char overlaps the box

1 Like

Version 4.13

Hello everyone,

I am currently working on a project of my game. I have been looking and searching for help about the AI Melee Attack Animation but I had found nothing helpful or workable for my Blueprint.

I am not making it complex at all, the AI is only going to play one animation montage that I had created meaning I do not want a behaviour tree. This animation montage does work, however, I do not know how to let the AI play the Animation Montage when he is near to the player.

In a more simple term, I basically want the Animation Montage to begin as soon as the Player as enter the Box Collision as known as Damage Range that I renamed.

Would it be possible for anyone to help my project, please?

I really need this urgent before next week.

Video I use to help me create the Damage: - YouTube

Thanks,

Kyle,

Hi,

Finally, someone answers my question.

I tried playing the animation montage of my punching animation, but the Enemy Fighter seems to be sliding when he goes to the Player.

I also get an error issue when this happens, in which is about the Affect Health.

I did a OnComponentBeginOverlap on the ā€˜Damage Rangeā€™ (Box Collision) and link out Play Anim Montage that plays the Punching animation.

You will need to set up an Animation Blueprint.
If you do not know how these work, either look up a tutorial, or check out the one used for the default player mesh included with the engine.

Once you know how this works:

  1. Create a Bool (and a matching bool in the Anim BP) called something like ā€œAttackā€
  2. When the enemy overlaps your player (or however you wish to activate the attack) set the bool to true
  3. In your Anim BP, create a state with the attack animation in it.
  4. Going into this state should require the Attack bool to be true, coming out of it back into the main animation loop should be the bool being false.
  5. In your attack animation, create a notify at the end of the animation (or the point you want it to end) called AttackEnd
  6. In your AnimBP, right click and search for AttackEnd to get the notify event for it, and drag off a Set Attack boolean and make it set to false.
  7. That should be it.

Doing this off of memory, so it might be a hair off.

Sorry, I am not used to using Animation Blueprint a lot.

I do not understand, why do I need to create a state with the attack animation if I got the Attack Animation Montage?

Can you try to provide screenshots, please?

I did use it, but the basics of making it run, walk, idle, jump and etc.

I just find other animations such as melee attacks hard for me.

Can you show me the Event Graph on how it works, please?

I understand more in visual then reading, especially when it comes to Unreal Engine 4.

Animation Blueprints are basically a must-use for animating your actors. Check out some tutorials on how to use them, it will save you a lot of hassle.
Basically, besides adding the boolean in the Event graph of the anim BP, you just need to add this Attack state like this to the existing Anim BP for the default mannequin

Your animation BPā€™s event graph would look something like this.

The ā€œAttack Endā€ notify needs to be created within the attack animation. Open your attack animation, right click on the ā€œnotifiesā€ bar towards the bottom (make sure you right click near the end frame of the animation) and hit New Notify (and name it Attack End or whatever you want). Then in your Anim BP, you can create the call to the notify like in the screenshot above.

Then just set up your character to set his attack bool to true when the button is pressed. Also throw in a check to make sure the bool isnā€™t already true, so the player canā€™t spam the button to continue the animation.

You can also use a notify in the animation to trigger damage, for example, if you are doing a punch, you can make a notify when the punch is in the middle of a swing, etc etc.

Oh, I remember seeing something similar this in the 3rdPersonBP tutorial when you are punching. I thought this only applies with the Player Character only.

This video I saw: BP 3rd Person Game: Animation BP Punching Setup | 18 | v4.8 Tutorial Series | Unreal Engine - YouTube

So I am using their punching animation and already created the montage for it. I just did not know how to set it up for AIs attack their animation because I thought the AIs setup is different to the Players.

I solved it with your solution and by the help of the videos. However, the punching is still looping when the Player is not in the punching range.

Hey everyone,

This was kinda solved, not 100% but in a way it did. I was only able to figure out for the animation to attack looping only, which still works if you are creating a game that focuses on the hands. I apologise for this confirmation to take long but I was really hoping for a reply from one of the issues I had encountered.

Many thanks to, palvand for creating a solution for it. It was not the exact thing I wanted because I still needed the character to stop looping after the player is out of the trigger box, but itā€™s better than nothing. I am sure some of you out there will find a way to fix it.

I hope my question helps people out there who was looking into it. Please remember this is on the 4.13 version of Unreal Engine.

Hey palvand the problem now is the NPC only plays the animation once per ā€œAttackā€ trigger, so he gets within range plays the animation and then stops until you move or shoot him again to trigger the attack. Any idea how I could fix that.