2D Player Animation (part 5)

Adding Attack Animations to our Player

For this article we are going to add an attack animation to our player and also learn how to toggle the animation via “Trigger” parameter.

Objective: Adding an Attack Animation to our player

Player Animation Setup:

Once you have slice and divided the animation sheet into individual frames, create a new animation clip and name it “Attack”. Then drag and drop all the frames into the animation window and set the frame rate to 30.

Adding all the frames into the Animation dopesheet and setting the frame rate to 30.

Then in the Animator window, we are going to create a new “Trigger” parameter name “Attack”. Create two sets of transitions from Idle to Attack and Running to Attack. Add the Attack trigger parameter as the condition, and also make sure that the transition to the Attack state must have no “Exit Time” and the Transition Duration has zero.

Player Animation and Player Script:

In the player animation script we are going to create a new public method that will toggle the animation Trigger.

In the player script we are going to create a new input function, and whenever the “E” button is pushed we will toggle the attack animation.

Now when ever we push the E button when the game is playing, the player will be able to swing its sword and do the attack animation.

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Versatility is your enemy

7 Software Engineering Traits More Valuable Than Coding

An engineer assisting another engineer with a question

Lesson 4: Essential Tools For Working With Distributed Teams

Number of Islands Problem

How spatial interfaces may change the face of softwares we use today

How do I apply a sample time to an array of values that represent data points at different times?

How to create Periodic Tasks in Celery?

On the whole there are three levels: common, epic and legendary.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Simon Truong

Simon Truong

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.

More from Medium

2D Player Animation (part 3)

Freeze Animation in Unity

Creating A Powerup in Unity

Unity new Input System : Player Input Component (Part XII)