Covered today: 2D Sprites and Sprite Sheets, Animations, Movement

So today I decided to work on the prototype for Cargo Bay 5 just so our team can start to get the “feel” for what we are talking about. I got a 2D character animated and moving across the screen for my first official episode of my Season/Shelf 05 streams.

2D Sprites and Sprite Sheets

Here is what I did to get this Bomberman spritesheet in my prototype:

  • Start off with a nice transparent spritesheet like shown above.
  • In Inspector:
    • Texture Type: Sprite (2D and UI)
    • Sprite Mode: Multiple
    • Slice (Top Left of Sprite Editor) and Smart Slice

If done correctly, you’ll have a nicely cut out Sprites (light grey box around each sprite). Click inside a grey box if dimensions are a bit off to edit it. Done!

I recommend whatever the size of your sprites are, you use the max width or height value as your Pixels Per Unit in the inspector so that your sprites fit in 1-by-1 Unity Units.

Another recommendation is to name each of your sprites… yup, it will be a pain in the butt, but will be worth it down the line.

Animations

Now that you have a bunch of Sprites, it’s time to animate them in a flipbook fashion.

There are multiple ways to create the animation, but the way I think I like the best (as of right now) is to select the sprites you would like in your animation, right click on a selected item, Click Create, Click Animation.

You should then have an Animation File (probably called New Animation). Assign this animation in an animator of a GameObject that already has a SpriteRenderer. Open up an Animation window, and you should be able to play around with the animation file some more. I believe you could also just drag New Animation onto a Sprite GameObject. Either way, now you can make multiple Animator States for the different states of your character.

Movement

Since this is a top down game, we will not be using any gravity. In this prototype I used RigidBody 2D and Box Collider 2D with Gravity Scale set to 0.

Then I created a script called Movement.cs to Animate the character and move the character using the RigidBody 2D.

In the final product, I do not recommend calling animator.Play() or rigidbody.velocty in the Update() function. But for now, attach the script to your GameObject with the Animator with the Animations and that’s it! We got a 2D Sprite moving and animating around in a 2D World.