Previously, we used the Sprite Editor to slice our sprite sheets into individual images. In your Assets, the sprite sheet should now contain all of its slices.
Each of these slices will constitute one frame of animation. To begin animating, we must first open the Animation window.
To organize my workspace, I like to dock the Animation tab in the Game window. Having the Animation tab below my Scene view allows me to work on animations while previewing them simultaneously.
I will begin by animating my tank’s tracks.
I start by selecting my player GameObject. Once selected, the Animation tab will prompt us to push the Create button to begin. After clicking the button, a window will appear where you will need to create an animation file. Name this file appropriately and click on the Save button. The Animation Clip will now be ready for editing.
Note: By creating an animation clip, Unity will automatically add an Animator Component to your GameObject.
Let’s take a look at the Animation window before we continue.
- This dropdown menu will give you access to all the animation clips associated with the Animator attached to the selected GameObject. You can choose other clips or create new ones in this menu.
- The sample rate is essentially the frames per second at which your animation clip will play. If you cannot find this option in your Animation window, you can enable it by clicking on the menu marked with the yellow dot. From the drop-down menu, you can select Show Sample Rate.
- The Add Property button will allow you to add parameters on your GameObject that you can animate. Every property can be animated individually.
Note: Any animated Transform properties will override all other movements.
- The Dope Sheet Timeline is where you will add keyframes to your animations. Changes in values between these keyframes will result in the illusion of movement.
With these things in mind, let’s finally start animating. My Tank Track sprite is already in the scene. The clip is saved and ready to be edited. The next step is to select the necessary image slices and drag them into the Dope Sheet.
That’s how simple it is. Let’s take a look at the animation to make sure it’s all working as expected.
Whoa! Much too fast! My animation consists of five individual frames. At a Sample Rate of 60, they will cycle through the five images seven times per second. We can correct this by changing the Sample Rate to a more reasonable value.
Much better. You can play around with this value as much as you need. Once you’re happy with the result, we can move on to creating more clips.
These new animation clips will be looping by default. If we wish to have them play only one time, we can change this by selecting the clip in our Assets, and un-checking the Loop Time field in the Inspector.
Finally, I will mention that by opening the Animator window we can see the animation state machine. This is a more complex topic that I will cover at a later date. For now, we can see that on entry, the clip we have just created will begin to play and loop infinitely.
In the case of my tank tracks, this is desirable behavior.
Note: The Animator window can be opened and docked in the same way as the Animation window.
After having created a few more animations, this is the current state of my Game, I think it’s looking very cool, and I can’t wait to get into more complex mechanics and animations!