I made a character in UE4, he has a run and idle animation with an animation sequence. I have been searching youtube like crazy on how to do this but they are all tutorials on old versions and they are not the same as UE4.18. My question is, I want to add a sword slash animation to my character so that when the left mouse button is clicked, it will play this animation,making the character look like he is in combat. How do I do that?
Hey there, you just need to have a variable in the character and in the animation blueprint called something like Is Attacking. On the character when you press LMB you set that variable to true, On the animation blueprint you need to use the Update event to update the Is Attacking variable of the animation blueprint to have the same value as the character’s. Then create a state Attack where the transition rule from idle to attack is if Is Attacking is true, if you want to be able to attack while running, add the same transition rule from Walk to Attack. To Finish you need to define the transition rule of Attack to Idle where you set the rule of if the time remaining of the Attack animation is less than 0.1 (for example) you do the transition. Don’t forget to set Is Attacking to false when the animation finishes so you can attack a second time.
Hey thanks for answering. I have already made a variable called Is Attacking on the ani9mation blueprint and the character event graph blueprint. How do I make the variable in the animation blueprint have the same value of the character’s? Thanks
Not yet, you need to drag a wire from Xavier DOTC and do a Get Is Attacking and connect that to the Set Is Attacking. On the LMB input event you set the Is Attacking variable to true. When you leave the Attack state you set it to false.
You need to connect the execution wire from the cast to the Set Is Attacking. For the LMB you just connect the Pressed to the Set Is Attacking to true, and for now you, you can do the Set Is Attacking to false on the Released.
I would just use animation montages for the attack instead of a state in the state machine, when you play the anim montage you set a timer with the duration of the animation to execute an event that sets the variable Is Attacking to false.