Search Unity

Adding clothes/weapons to my player sprite

Discussion in '2D' started by HatchetMan302, Apr 27, 2016.

  1. HatchetMan302

    HatchetMan302

    Joined:
    Apr 27, 2016
    Posts:
    2
    I am able to have a guy that walks around and can do a slash attack, but I am stumped on how to get clothes on him as separate sprites. My conception is something like layering 2 sprites on each other and having each follow the other, in this case have the clothes follow/mimic the player. Is there a way to do this?
     
  2. Hyblademin

    Hyblademin

    Joined:
    Oct 14, 2013
    Posts:
    725
    The method you described is applied in basically all cases for this purpose. Are you having trouble with it?
     
  3. HatchetMan302

    HatchetMan302

    Joined:
    Apr 27, 2016
    Posts:
    2
    Ya. I tried using animation layers, but I don't understand those very well and got lost fairly quickly.
     
  4. Hyblademin

    Hyblademin

    Joined:
    Oct 14, 2013
    Posts:
    725
    I see using a separate animation layer as one valid method of accomplishing this, but I think it's more commonly used for when more than one distinct state machine needs to run simultaneously, like with animating arms and legs independently in 3D models.

    I think it would make sense for the clothing to be its own object that is a child of the character that they should be worn by. When the character changes equipment, you can tell the clothing object to change its sprite set to the matching set. It would have its own animation controller and animations (which keep them in the correct position on the character's body as it moves around), which are run at the same time as the character's animations.

    Just in case you need to see it, there's a quick example here; the clothing is all animated as if it was worn, but does not include the character itself. It's then put on top of the character sprite with the correct offset, and animated simultaneously.
     
  5. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    I'm not sure if this is precisely what Hyblademin is talking about, but if you animate your character as a sort of skeleton of gameobjects, then you can make your clothing and weapons children of the different gameobjects in the skeleton, and you'll only have to animate the skeleton. This is similar to how 3D characters are rigged.

    So your shirt will be a child of the "Chest" gameobject, your weapon will be a child of the "Hand" gameobject. And you will animate the "Chest" and "Hand" gameobjects as part of the characer's skeletal rig (which is just a hierarchy of gameobjects. Then if you need to swap weapons, it will be as simple as replacing the weapon object with a new one.

    The reason I say swap the object and not just the sprite is in case your weapon is comprised of more than one sprite.

    See this stickied post: http://forum.unity3d.com/threads/2d-puppet-rigging-tips-tricks.245564/
     
    Hyblademin likes this.
  6. Hyblademin

    Hyblademin

    Joined:
    Oct 14, 2013
    Posts:
    725
    Yes, but as it applies to purely spritesheet-animated actors instead of puppets. It's unclear which one OP is using, now that I look again.