Search Unity

Single-Sprite Idle Animations

Discussion in '2D' started by zalwicker, Nov 11, 2019.

  1. zalwicker

    zalwicker

    Joined:
    Sep 13, 2018
    Posts:
    2
    I'm currently attempting to animate my sprite that moves in 2D in 8 different directions. My animations for walking work fine. However, I cannot find an easy way to achieve the idle states, which each consist of one sprite that has no animation.

    I'd like to try to avoid creating an animation for each idle sprite if it is only one frame, but so far I have not been able to find a suitable solution.
     
  2. MisterSkitz

    MisterSkitz

    Joined:
    Sep 2, 2015
    Posts:
    833
    You should be able to animate your idle as well. If you use a State Machine to dictate your animations then you can easily switch between states. How are you currently playing your animations?
     
  3. zalwicker

    zalwicker

    Joined:
    Sep 13, 2018
    Posts:
    2
    Currently I have two blend trees, one for idle and one for walk. The blend tree takes two parameters, X and Y which indicate the direction of movement and then provide animations from there. The idle animations would be set up the same the same, except I want to avoid creating a new animation as each idle position is one sprite.
     
  4. MisterSkitz

    MisterSkitz

    Joined:
    Sep 2, 2015
    Posts:
    833
    Then use Euler(), eulerAngle(), or .rotation to rotate your player to the direction you want to face. I'm curious actually if the idle animation would respond... Now that I said that out loud...
     
  5. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    359
    Hi @zalwicker,

    I hope you already read https://blog.redbluegames.com/animating-top-down-2d-games-in-unity-5e966b81790e
    I will say there is no "good" way to avoid 8 clips for idle animation.

    So, for example you can put 8 frames of idle animation into one animation clip, and play single key frame at position, and stop animation if no direction arrow pressed. Animation.play(1,-1, frameOffset); Animation.Stop().

    But it is jaggy solution. I personally don't use AnimationStateMachhine, and I use sprite mirroring, so its only 5 clips to work with. But is a lot of code to manage.
     
    MisterSkitz likes this.