I've decided to split the player attack explanation into multiple parts, as there's quite a lot to go through. This part will mainly explain how the animations are played for the player's attacks & the notifications into the PlayerController.
I decided to use an Animation Montage to put together the sword attack combos. For this temporary asset, I only had the 1 attack animation so to create the combo I added the animation multiple times into the montage, reversing the next animation for the follow-up attack. I then trimmed each animation so it flows directly into each other and split each part into sections, and by the end the sections looked like this:
I decided to use an Animation Montage to put together the sword attack combos. For this temporary asset, I only had the 1 attack animation so to create the combo I added the animation multiple times into the montage, reversing the next animation for the follow-up attack. I then trimmed each animation so it flows directly into each other and split each part into sections, and by the end the sections looked like this:
By default, each section will play an animation and if it is not told to play another section it will play the wind-down animation and end the attack.
For the next part of this montage I needed to add the notify events so that the state can be messaged when the attack end, when the animation is complete and when the attack should be activated.
For the AttackComplete and AnimationComplete events I used a basic Notify, whereas for the Attack active state I used a NotifyState - this way I can make the attack active with the NotifyBegin and NotifyEnd methods.
I created a subclass for the NotifyState which is used to notify the PlayerController about the attack becoming active using a message. Currently, the NotifyState only works with the PlayerController but in the future I might need to refactor this to be more generic. In the end, this class looks like this:
For the next part of this montage I needed to add the notify events so that the state can be messaged when the attack end, when the animation is complete and when the attack should be activated.
For the AttackComplete and AnimationComplete events I used a basic Notify, whereas for the Attack active state I used a NotifyState - this way I can make the attack active with the NotifyBegin and NotifyEnd methods.
I created a subclass for the NotifyState which is used to notify the PlayerController about the attack becoming active using a message. Currently, the NotifyState only works with the PlayerController but in the future I might need to refactor this to be more generic. In the end, this class looks like this:
I added multiple null checks into the GetPlayerController method to ensure that the PlayerController is valid, and I send the attack start & end message through to the player controller if it is.
I then added the notifications into the animation montage at key points during each animation, so the final result looked like this:
I then added the notifications into the animation montage at key points during each animation, so the final result looked like this:
Now with the montage setup I needed to add the montage to the animation blueprint. First, I updated the AnimGraph to play the montage between the default pose like so:
I assigned the slot to be the AttackSlot that I defined, and hooked up the animation to the final animation pose.
I then updated the EventGraph for the new animation to allow for sending messages to the player controller after the montage events:
I then updated the EventGraph for the new animation to allow for sending messages to the player controller after the montage events:
I added three variables to the blueprint - an FName for the Attack completing, an FName for the Animation completing and a PlayerController instance. I added the PlayerController so that I wouldn't have to continuously cast the controller for the notifies.
I then implemented the BeginPlay method to obtain the player controller & set it.
Finally I added the events for both AnimNotify events which will simply send a message to the player controller.
The animation blueprint & the animation are now both ready for the attacks! The next post will discuss the implementation of the Attack state.
I then implemented the BeginPlay method to obtain the player controller & set it.
Finally I added the events for both AnimNotify events which will simply send a message to the player controller.
The animation blueprint & the animation are now both ready for the attacks! The next post will discuss the implementation of the Attack state.