Adventures in GameDev with GameDevHQ Day21: Animating sprites in Unity
One of the latest lessons is learning how to animate a powerup that gives you the ability to Tripleshoot. At the moment, it falls down the screen because it only has a sprite attached to it.
Cool, but there’s no life to it. Fortunately, we have various frames that make it pop available in our project window.
Animating in Unity can be a daunting process but for what we want to do, it’s fairly straightforward. The steps are selecting the powerup gameobject, opening the animation window, creating a new animation, and then adding those frame images into it. We’ll go into this step by step:
After selecting the game object, let’s open up the window and dock it by the Game View window below the scene view.
While the powerup is selected, you’ll see there’s a message that if you want to create a new animation, just click the create button. So do it!
It will open up a file window, it’s generally a good idea to create a special Animation folder in your Projects window, being organized in your project should be your first priority, because a few sprites and animations now will potentially turn into thousands of assets later and you’ll be pulling your hair out looking for a specific needle in your projects haystack if you don’t have things well organized! That said, I went a little overboard by creating an Animations folder, then a PowerUps folder (because you can’t have just one), and the TripleShot folder where all the animations will be located at. This particular powerup will only have one animation but many game objects have two or more depending on their state.
So now you’re greeted with a timeline view of your empty animation. Now what? Simple! Just select and drag all of the frames of the animation into the timeline and you’ve just created an animated gameobject!
As you’ve seen, there’s an animation control system to the left that you’re familiar with if you’ve ever used a vcr or dvd player or animation program. Just hit the play button and you’ll see your game object come to life!
Personally, I think the animation is running a little too fast, the most direct solution is to lower the sample rate of the animation to make it run slower. Right now it’s 60 frames per second, let’s halve that to 30.
Ahhhh, much better! Since it’s a prefab, don’t forget to hit override so all powerups become animated. Now let’s see it in action!
Awesome! We’re getting a more professional looking videogame every day!