Animating our Player part 2 and Camera Control

Jordan Evans
Sep 24 · 4 min read

Now that we have our basic animations implemented, let’s take a look at putting in some attack animations.
The first we will work on is a basic swing of the sword from either running or idle state. This is a pretty simple one to put in place, as we are going to have it act as a trigger event. To start, we will place it within our animator window and make a couple adjustments to the order of which our different events are laid out just to make it a little cleaner:

Next, we will go into our script and create the logic behind our attack:

With this in place, we can now check how it looks in our game:

Now that we have our attack motion in place, let’s see how we can implement a method to have some effects that go along with our swinging of the sword. To start, we are going to create a new sprite under our player and adjust the values and speed at which our sword arc looks:

Next, let’s look to connect it to our animation by first creating a parameter that is needed for it to activate:

Now let’s take a look at how we go about coding it:

When we are looking to grab our animator from a different child object, we need to change how we grab our component slightly. What we are telling Unity is that we want to grab our animator from a specified object. Now that we have this set up, we can test it within our game:

So, we have a working animation, however it is not in sync with our player’s swing. In order to adjust this, we can look at a few different methods to get it all to work together. Eventually, we can get our animations lined up like so:

Next up, let’s get it so that with our player, the sword arc animation plays on the proper side:

As we can see, it only plays on the 1 side of the character. To change this, we need to adjust a few aspects of the object so that it can rotate around whenever the player changes the direction:

As we can see, we simply just flip our object on the x and y axis, along with change the position of the sprite on the x to either positive or negative depending which way we are facing:

Now that we have our animation with the sword attack and it’s vfx working, let’s quickly add in a CineMachine camera to follow our player around with:

Now that we have our camera following the player and an attack animation set up, we can now look towards adding in some enemy elements to our game.

Nerd For Tech

From Confusion to Clarification

Nerd For Tech

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/.

Jordan Evans

Written by

Nerd For Tech

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/.