A few beginner questions (animation and inputs)

Hello, I am new to unity and somewhat new to scripting (coming from a c++ background and writing a game on a standalone platform, but ive never used scripting within another software before)…

I have a few questions, and was hoping someone could either answer them or point me towards the appropriate resources so I might better educate myself (as I have tried looking this stuff up for myself but had some difficulty sifting through and comparing different resources/methods).

My questions are

  • How do you set a resting frame for a sprite (with no button press)? So far I’ve figured out how to animate my sprite, but as soon as I start my game it immediately loops through continuously… I wanted it to display frame 0 unless a button was pressed.

  • How can you mirror sprites and add them to your animation? I’m currently not using a sprite sheet and went with using individual sprites/frames… at the moment I have frame 0(resting), frame 1, then frame 2… but I wanted the order of frames to display as 0,1,2,1,0, etc…

I have a few more questions as well pertaining to button inputs (which may need addressed to answer my first question), but didnt want to get to far ahead of myself yet so will leave it st that for now. Thanks!

Hi @CatDadJynx

“I wanted the order of frames to display as 0,1,2,1,0, etc…”

You create animation clips, in which you set keys for sprites or some other values in order to create frame based animations. You can order the frames any way you want. You can also create as many clips as needed.

“How do you set a resting frame for a sprite”

Unity has animation system. To create animations with different states / clips you can use Animator component. Note, there is also old Animation component, which works in completely different manner. Animator is a state machine like system.To create a “idle” state, you create a state in animator where you assign your idle animation. Then create other states you need. Then create transitions between states. Then set your conditions for each transition. Transition from idle to walk (for example) would happen when speed is greater than 0 (for example), to make this happen, you would change a speed variable in your animator, from your C# code. See Animator manual / tutorials for more info, there are several tutorials available.

Of course nothing prevents you from creating some script that plays frame sequences, so you can create a custom sprite animation system if need be, if you find Animator to be too high level system. I’ve done this several times myself.

“How can you mirror sprites and add them to your animation?”

You can flip sprites by setting GameObject’s transform x/y scale to -1. Or you can use SpriteRenderer’s Flip x/y option. You could also animate these values in your animation clip in addition to changing sprite frames.

1 Like

Some links that may be useful:

1 Like

Thank you both! I’ve managed to get all my animations working and attached to one game object, now I’m moving on to controls. Thanks!

1 Like