Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Creating an equipment system on a 2D pixel game

Discussion in 'Animation' started by Mika_Do, Apr 1, 2015.

  1. Mika_Do

    Mika_Do

    Joined:
    Apr 1, 2015
    Posts:
    9
    Hey guys !

    So here's my problem:
    I'm making a 2D pixel game where the player is able to buy and equip stuff. He will be able to buy weapons, shirts, pants, ... All these parts can mix randomly (top A with pants B and shoes C). I would like to know what's the best way to do this ? I'm currently stuck at the animation part...

    My animations are made such that the character is naked at first and each equipment is put on the object in a separate layer. Each equipment has a separate animation (walking, running, ...) and they all play at the same time on the same object. (Like this: http://gyazo.com/9a60cd59ba6e86fb0162d185be6c0b02, we can't see it well because of the background but you get the idea). I know it's not a good solution and that's why I need your help :(

    I think (and hope) some people already asked such question and it has already been answered. I searched through the forum but didn't find any answer... If any of you has an anwser to this or had a link to an answer you will become my hero !

    NOTE: The results I'm trying to reach are a bit like in Starbound. A character can equip different parts and these are just pasted over the character. As in Starbound, I'm not using bones, so this is not an option...

    Thanks a lot !
     
  2. Redden44

    Redden44

    Joined:
    Nov 15, 2014
    Posts:
    122
    Hi, you could split the body of you character into different parts (head, face, chest, right arm, etc) and move/rotate/scale them to animate your character; when you want to equip a different armor you can just change the sprite of the slot.

    For example you can have an epty Game Object as the chest slot with a naked chest image as the sprite of the Sprite Renderer component; if you want to equip a jacket, you just change the sprite of the Sprite Render.

    Check this thread: http://forum.unity3d.com/threads/2d-puppet-rigging-tips-tricks.245564/
     
    Pierry and theANMATOR2b like this.
  3. Mika_Do

    Mika_Do

    Joined:
    Apr 1, 2015
    Posts:
    9
    Thanks for your answer Redden44, but as I said this is not what I'm trying to accomplish :/ Using bones in a pixel game doens't look good, I tried it :p Seeing pixels rotating looks weird ^^
     
  4. dustinandrew

    dustinandrew

    Joined:
    Apr 30, 2010
    Posts:
    87
    You could create each equipment as a layer in your animation controller. Then have a bool parameter in each layer that would show or hide the layer. Then in each layer, the equipment checks to see what animation state they need to be playing.

    The only issue I would see with this is because you are using the same animator, all your equipment frames need to line up with the character. So make all the frames the same size & line up and it should work.
     
    zs8861 and TonyLi like this.
  5. Mika_Do

    Mika_Do

    Joined:
    Apr 1, 2015
    Posts:
    9
    I already made sur all my equipment and animations line up perfectly when I made them so this will not be a problem :D

    Alright this is what I was thinking to do, I just wanted to make sure there were no better solutions... Thank you very much dustin !
     
  6. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,781
    Hey Mika_Do
    I dont mean to be contrary but the better solution IS using bones (hierarchy) - so the swapping can be accomplished easier/better.

    I've actually never heard the point you raise that bones used in a 2D game look wierd because of the rotating pixels.
    Thats very interesting.

    I've heard/read several times devs prefer the snappy results of sprites compared to using bones because of the smooth frame interpolation that results from 'rendering' instead of each sprite being drawn. Though this interpolation can be edited depending upon the curve function used.

    Never the less - I hope you find a good solution that works and is optimized.

    Looking forward to watching your progress.
     
  7. adsilcott

    adsilcott

    Joined:
    Aug 30, 2014
    Posts:
    17
    Hey Mika_Do, it seems that no one really understood the problem you were having. I do, I'm trying to do the same thing: I have a sprite sheet with the character layer, the weapon layer, and an effect layer. They are all 64x64 tiles, all lined up so that if the animations are played together everything lines up perfectly. Right now I'm merging all the layers on export so they can be played by one sprite renderer, but I'd like to separate them so I can swap out weapons or apply a tint to only the effect layer, etc.

    I can't even figure out how you got those multiple sprite animations into one like in your screenshot. I can add multiple sprite renderers attached to child objects as properties in the animation window, but they just show the static image that the sprite renderer is set to. How did you get multiple animations together like that?

    Could you describe how you did that, or what you ended up doing if you found a better way? Or someone else who has figured out how to have one animator control multiple simultaneous sprite animations (not transform animations).
     
  8. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    9,109
    dustinandrew's is the best approach for sprite layer-based animation. Use synced layers to make the animator controller easier to manage. (See Animation Layer Syncing at the bottom of this manual page.)
     
    RemDust and theANMATOR2b like this.
  9. qiqiqi

    qiqiqi

    Joined:
    Nov 3, 2015
    Posts:
    5
    Hi Mika, I'm having the same problem, and I understand that pixel art + bone animation looks weired. However drawing frame animations for every equipment combination is kind of impossible.
    I wonder how you end up of doing this? I would appreciate if you can share any ideas.
     
  10. JhitoStudio

    JhitoStudio

    Joined:
    May 5, 2016
    Posts:
    17
    Any update on this?i would love to get the solution because my animation is also based in frame by frame construction
     
  11. skauth

    skauth

    Joined:
    Jun 4, 2017
    Posts:
    16
    Hey, I know I'm a bit late to the party. But so is Unity apparently. 'cause they focus on 3d more than pixel art. Oh well, that's them. And people who pay for Unity probably want 3d, who knows.

    Anyways... I just posted a partial answer to this very problem on the gamdev.stackexchange ... I'm still working on it, so I can't verify that it works. But it's what I'm planning on doing. For those who are are a bit confused on what the original question was, take a look at this LPC character generator for the general idea, and this github repo of LPC SpriteSheet Layers for more clarity. Every bit of clothing, every weapon, every body base is a different texture, roughly the same size (though some are smaller because they don't have all the animations.)

    Following is what I posted on the GameDev.stackexchange question.

    (Open Spoiler for a tangent!)

    As a follow up thought, testing will probably involve making about 200 characters and giving them a random number of accessories between n1 and n2, where n1 and n2 would be benchmark measures for between maybe 3-5 accessories, and 20-30 accessories to see if there's any significant difference. They would of course each be doing random animations and movements. If I'm not getting any problems there, I'll up it to 2000 characters maybe? But I won't give any of them interactability with each other. Because I'm almost certain that collision detection or even distance checking with singular targets between 2000 characters is gonna be waaaay more resource intensive than having 60000 individual animated sprites on the screen. 200 characters on screen sounds like a lot, right? Well sure. But maybe my hefty development desktop with 16GB of ram and a dedicated graphics card can handle 200 without lag while my girlfriend's brothers netbook's internet browser WebGL will only be able to handle 4 characters on screen before lag takes over. Benchmarking is noting a significant difference between two options, not simply verifying that one option works on a given condition.

    Also, instead of having 5 different race textures, 20 different shirt textures for the same shirt in different colors, etc, I can lower the number of textures by setting them all to light-gray/white and applying a color to the sprites.