2D Movement Animations in Unity

When you get the player moving you will want to add animations. To do this open the animation window and dock it next to the console.

With your sprite selected hit, create a new animation for your sprite. This will create an animation and add an animator to your sprite.

Now make sure to splice your sprites correctly, hit record in the animation window, and drag the sprites in.

Note: The Sample can be used to speed up or slow down the animation

Double click the animator controller and it will pop up for you. Set up your animator to have the idle transition to and from run depending on a speed parameter.

Note: Turn of transition exit times and transition durations

Create a script for your animations and add it to the game object your sprite is under.

Get a reference to the animator and create a method that takes in a float value and sets the float value for the speed parameter for the animations.

In the player script, get a reference to the player animation script. After setting the velocity of the player pass the horizontal movement into the move method.

This will get the animation transitioning between idle and running.

The last thing to do is to flip the sprite according to the direction the player is moving. To do this, get a reference to the player’s sprite renderer. Create a method in the player animation script that will take a float value. Depending on the value the player sprite will be flipped along the x-axis.

This will get the player moving left and right and have the sprite facing the right way.




Unity Game Developer and C# Programmer

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

Recommended from Medium

Conditional Statement — Python

Spark Streaming part 2: run Spark Structured Streaming pipelines in Hadoop


Building my personal cloud after 4 years

CS373 Software Engineering Blog #11

BloC Architecture in Flutter: a Modern Architectural Approach and How We Use it at Jimdo

How Live Collaboration Coding Tools Will Boost Your Pair-Programming Efficiency

How to Fixing Error urllib3 (1.26.4)

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
Matthew Clark

Matthew Clark

Unity Game Developer and C# Programmer

More from Medium

Adding a new ability to our prototype — The Triple Shot

Instantiating & Destroying Game Objects in Unity

Animating Sprites in Unity

My journey becoming a Unity game developer: Make a game look beautiful-Scifi Control Room Floors