Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

How to build a layered animated sprite

Discussion in '2D' started by Jinxology, May 28, 2016.

  1. Jinxology

    Jinxology

    Joined:
    Jul 13, 2013
    Posts:
    95
    I'm building the following animated (see below). The sprite consists of a body with varying pixel art (ie. the legs are not just animated, it is different art), and a head, weapon and shield that move but the art does NOT change, only the position does. The body will never change, but the head will change quite a bit. Hair and face will pull from a random bank of 15-20 options to create variety.

    The sprite currently has 3 states: Run (what you see below), Stand (no movement), Attack (different animation entirely)

    What is the best way to build this in Unity? I am currently creating 3 Animations for the body (run, stand, attack), 3 for the head, 3 for the sword and shield, then I plan to change the animation used via script. I create an empty parent object and stack the Body>Stand animation, the Head>Stand animation, the Hair>Stand animation, the Sword>Stand animation, etc.

    I can't help but feel that this technique is cumbersome. I'm looking for advice and best practice for doing this. Thanks!
     
  2. jc-drile77

    jc-drile77

    Joined:
    Jul 1, 2014
    Posts:
    230
    You can create a bone system using parents and childrens, so that you can have just 3 animations "Run","Stand","Attack" and 1 animator.
    The structure would be something like

    Sorry for using the code tag, but it is the only way format remains as it should be
    Code (CSharp):
    1. Character (animator)
    2. |->Body
    3. |    |->Head
    4. |    |         |-> Hair
    5. |    |         |->Face
    6. |    |->Right arm
    7. |    |         |->Sword
    8. |    |->Left arm
    9. |    |          |->Shield
    10. |    |->Legs
    In each animation you would modify the position of the each transform or change the sprite of the sprite renderer if needed, as each part is a children of the Character gameObject you can easily achive this in the inspector with just 3 animations.
     
  3. Jinxology

    Jinxology

    Joined:
    Jul 13, 2013
    Posts:
    95
    Thanks, that did the trick. My confusion comes from the difference between needing to swap out a single Sprite in that scenario vs. needing to swap out an Animation Clip. Since everything below the body was static and moved only via position, that solution works. If the head graphic was an animated clip, I'd probably still be a little confused. I did, however, find some code to swap out animation clips which is nice.
     
    theANMATOR2b likes this.