Search Unity

Best way to do multiple layers of clothes?

Discussion in '2D' started by Justin-Whitney, Jan 22, 2019.

  1. Justin-Whitney

    Justin-Whitney

    Joined:
    Jun 10, 2013
    Posts:
    6
    I'm trying to learn the best way to set up the foundation for a 2d rpg and am trying to figure out the best way to set up the layers for the characters. If I am to have armor that can be worn on adventures and clothes for in town activities or even interchangeabe armor sets, what's the best way to do this? Should I just spaces out the limbs and body parts in every 10 or so to add stuff or should I have them on there own layers such as character_base, character_clothes and character_armor layers?

    Does anyone know of any good resources or tutorials I could follow? or even good resources for creating in game inventory management? I don't have much experience coding but can try to figure out how take apart existing code if there is a code foundation.
     
  2. Primoz56

    Primoz56

    Joined:
    May 9, 2018
    Posts:
    369
    i'm using a fantasy character pack which does most of what you want, and very cheap. you can then reverse engineer it to get a proper understanding.

    as far as i know there is no 'best' way, and there are many options, but either way you'll want to layer your images on top of each other and create some form of skeleton or nodes around which you rotate and transition you limbs etc.
     
    Justin-Whitney likes this.
  3. hlw

    hlw

    Joined:
    Aug 12, 2017
    Posts:
    250
    If your camera is set to orthographic, you can modify the sorting layer, the order in layer, the Z transform position and the hierarchy order of your gameobjects to decide which sprite gets drawn on top of the others. (I do not recommand using the hirearchy order tho)

    IIRC there is a limited number of possible sorting layers, so you should at least make a good use of the order in layer setting if there is a lot of sprites you need to sort. Modifying the Z position will then only change the order of sprites that belong to the same sorting layer and same order in layer, you coud use that if, for examples, some items belonging to the same layer might get on top of each other based off animations timings.
     
    Justin-Whitney likes this.
  4. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,702
    It's much easier if you're using skeletal animation with different body parts:


    (Image above is from Ray Wenderlich's tutorial.)

    When the character puts on a breastplate, just replace the torso sprite with a breastplate sprite, or layer it on top.

    If you're doing cel-based animation (typical with pixel art characters), you'll need a separate layer for each piece of equipment or customizable body part. Here's an image from an Asset Store package that does this:



    The character in the upper right was composed with six overlapping layers (skin, eyes, hair, shirt, skirt, shoes). Each layer needs all the animation frames for every animation, so it ends up being a lot of frames.


    In either case, you can get a lot of mileage out of using the same images and changing their colors. Here's a post that describes how to use a shader to customize certain colors in an image. You can find shaders on the Asset Store that do this if you don't want to dig into shader coding.
     
    Justin-Whitney likes this.
  5. AssembledVS

    AssembledVS

    Joined:
    Feb 23, 2014
    Posts:
    248
    TonyLi's post addresses your question pretty thoroughly, I think.

    It also partly depends on whether you're using a pixel art style or something that is more usable with the skeletal animation system. You'd obviously want separate spritesheets for every piece of clothing, skin color, hair, etc., as the combination of different parts would be far too numerous to have each combination have its own spritesheet.

    In my pixel art game, skin color, clothing, etc. are simply re-skins or re-colors and the pixel boundaries do not change from one combination to the other. Each part, like the clothing, the skin, etc. will be its own Game Object that is independently animated. Game Objects are switched on and off to create what looks like a single cohesive sprite. I tested this a while back on a small scale and it seems to work just fine.
     
    Justin-Whitney likes this.