Objective: Set up Sword Arc Animation when Attacking
The above image shows the Player mid attack, swinging the sword. Below is a spritesheet of an FX style that we can add to the Players sword swing to make it look bettter.
We follow the same process as before to slice the image and create the frames for the animation. Next drag the first frame image into the hierarchy, rename it to SwordArc, select it and create a new Animation Clip. We will get a new Animator Controller. We also create a new empty state and set it as default as we don’t want the sword arc to run automatically, then we set up the transitions and parameters like we did previously.
Open the PlayerAnimation script and create a new private Animator and SpriteRenderer for the sword and assign them in the Start method, only this time using the transform GetChild then GetComponent as otherwise we would still get the ones associated with the Player.
In the Attack method set the SwordAnim trigger after the PlayersAnim attack trigger.
Currently the animation is a bit off but it works. We need to adjust the rotation of the animation and also do some sprite flipping like we did with the Player when turning/facing left.
After some trial and error the with position and rotation of the sword arc we ended up with the followng values that worked better and give the result shown below.
To fix the flip we edited the FlipSprite method to change the sword renderer flipY on and off and set the transform of the sword arc depending on which way the Player was facing.