Search Unity

RPG with multiple weapons

Discussion in 'Animation' started by HellGamer115, May 9, 2014.

  1. HellGamer115

    HellGamer115

    Joined:
    Jan 9, 2013
    Posts:
    9
    i have a big problem with the game im trying to make, i want a character with multiple weapons but i don't know how i would make the character hold the weapon. i was thinking of modelling the character with the weapon and then importing it into unity has 1 model but then i don't know how i would do it for multiple weapons. i know how to blend animations, but i don't know if i can change the upper model of the body. is there anyway that i can change the top of the characters model? or should i model the waist down of the character then the upper body separately then switch the upper body to a different model everytime i switch weapons.
    i read about IK where i can attack a sword to the hand but i don't want to do it because i have multiple weapons and i have two handed weapons.
    please someone help me
     
  2. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,697
    The two common approaches are:
    1. Include all weapons and equipment as additional meshes in the original model. Hide all meshes except the ones that are currently equipped.
    2. Use attachment points -- that is, child GameObjects positioned at the hands -- that you can child the weapon objects to.
    Either way, you'll probably want separate animations for hands open (empty) and closed (gripping a weapon), as well as animations for holding two-handed weapons. You can use IK to procedurally adjust the hands into position, but you'll need Unity Pro to use the built-in Mecanim IK, or something like Final IK (or write your own).
     
  3. HellGamer115

    HellGamer115

    Joined:
    Jan 9, 2013
    Posts:
    9
    is there a video tutorial? im a big noob at this stuff i only gotten so far with piecing together different tutorials. also i want to animate the arms for each model differently because i seen mecanim IK for swords and they look really bad. but could i possibly make the character in halfs. so the bottom part is always the same but the top changes with every weapon so i can use your number 1 solution? hiding the rest of the tops and only show the ones i need.
    also i want to change the colour of the characters clothes, so can i just change the texture?
     
  4. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,697
    What you're asking is a tall order, but in the end it's not too hard. It just involves a lot of parts.

    It's like Jean-Baptiste Queru's article "You just went to the Google home page." When you go to Google, you use HTTP, HTML, CSS, and more. And below this you use DNS, TCP, Ethernet, etc., below that is your local browser software, OS, hardware drivers, etc.

    Unfortunately I'm not aware of a single resource that covers everything you're asking about.

    tuts+ has an Overview of 3D Modeling. Scroll down about 75% of the way to "Animation in Games" to read about how WoW uses sockets (attachment points).

    To animate the lower and upper bodies separately, you'll need to use layers and avatar masks.

    masterprompt wrote an overview on stitching together meshes. In your case, however, you might just want to activate and deactivate the meshes' GameObjects as characters equip items.

    Also, look into the Unity Multipurpose Avatar (UMA), which is a customizable model system. A lot of artists have already created equipment and skins for it.
     
  5. HellGamer115

    HellGamer115

    Joined:
    Jan 9, 2013
    Posts:
    9
    ok lets say i was to use unity's built in mecanim IK, should i create idle animations for all of the weapons? just for the hands. so i can use body mask? so if i switch weapons it would play that idle animation but how would i position the weapon inside unity? thats what im wondering because if i create an empty game object and attach a sword to that gameobject and make it look like the character is holding the weapon, how would i do a crossbow? do i have to create another empty gameobject and position the crossbow? or is there another way to do this?
    im sorry if this is not making any sense at all, im very confused on how to do this.
     
  6. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,697
    Note that you need Unity Pro to use the built-in IK system. If you're using Unity (Free), you can buy Final IK instead.

    With IK, you usually add some attachment points to the weapons themselves. With a crossbow, the attachment points might be at the trigger and somewhere down the "barrel." Then you position the weapon, usually relative to the character's hips or shoulders, and then use IK to "glue" the hands onto the attachment points. If it's a two-handed sword, the attachment points would be on the hilt where the character should hold it.

    You can also attach the weapon to an attachment point on one hand and use IK to adjust the position of the other hand. Going back to the crossbow, attach it as a child of the character's trigger hand. Then use IK to "glue" the other hand to the barrel. In this case, you'd play a "holding crossbow" animation that would position the trigger hand correctly. The IK-controlled hand would just follow along.

    Depending on your needs, you might find it easier to skip IK and just create separate upper-body animations for each weapon. This will allow you to position the hands perfectly for each weapon's animations.
     
  7. HellGamer115

    HellGamer115

    Joined:
    Jan 9, 2013
    Posts:
    9
    are the IK positions saved? so if i just set up the weapons in the editor, how would i save the IK position? do i have to make an idle animation for the weapon so when im switched to that weapon it would look like the character is holding the weapon or if i just adjust the IK position in the editor, is it saved automatically
     
  8. HellGamer115

    HellGamer115

    Joined:
    Jan 9, 2013
    Posts:
    9
    do you think you can help me after a few weeks time? im doing my exams now but afterward. if i make all the animations and everything, do you think you can help me out a bit? im making a torchlight/diablo style game, i got all the xp and leveling up sorted out and i can finish the weapon models as well.
    thank you for helping me out so far :D
     
  9. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,697
    PM me when you want to work on it. If I have time available I can do my best to get you pointed in a good direction.
     
  10. HellGamer115

    HellGamer115

    Joined:
    Jan 9, 2013
    Posts:
    9
    thank you so much man, my exam will finish mid next month so after that i will send you a PM because right now i can only work like 30 minutes a day on the game so i don't want to waste your time.
     
  11. HellGamer115

    HellGamer115

    Joined:
    Jan 9, 2013
    Posts:
    9
    hey man i just need to ask you 1 more thing, is there anyway that i can make a map editor for the users? so after i finish my game is there a way that they can make their own maps maybe using unity them self and exporting it to a file and make the game read the map from a file or load the scene from a file.
    btw i won't be needing this for at least 6 more moths but i just want to know.
     
  12. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,697
    There's always a way! :) It's a big topic, though, and maybe something best to save for a follow-up game. If they create maps in Unity, you could provide an in-editor exporter tool to save maps, for instance in XML format. Then your game can read the XML to load the map.
     
  13. HellGamer115

    HellGamer115

    Joined:
    Jan 9, 2013
    Posts:
    9
    ok so i think i got the idea, if i were to do this, i would need to give the players the prefabs for spawn points and enemy spawn points right? anyway thanks for the help
     
  14. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,697
    Right, or stand-in prefabs. When you load the map into the game, you could always load the real prefabs instead of the stand-ins.

    Another option is to support map editing in-game. The advantage is that players don't need to install and use Unity. The disadvantage is that you have to build the editing interface in your game.
     
  15. Croomraider

    Croomraider

    Joined:
    Sep 14, 2016
    Posts:
    28
    @TonyLi
    What's the latest on the multiple weapons, as of now 2017 Unity?

    I read over all of this thread and at least have an idea of knowing I need to research more about "IK" as I don't have a clue of what it is, lol.

    I'm doing a 2D platformer and am hoping to change out weapons as the character finds them.

    When you say "hide all meshes except the ones that are currently equipped" -- do you mean in photoshop while prepping the image sequence or sprite sheet..... or is this an idea for code that would essentially bypass hidden meshes and load up the visible mesh (current weapon)?
     
  16. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,697
    If you're doing 2D, none of this applies. 2D is typically done two ways:
    • Sprite sheets (cel animation): (Example: Shovel Knight) Use a separate sprite sheet for each version of the character holding a different weapon, or layer sprite sheets such as layering a helmet sprite sheet on top of the base character sprite sheet.
    • Skeletal animation: (Example: Plants vs. Zombies) Each body part of a separate GameObject organized into a hierarchy. The animation defines how the GameObjects rotate in relation to each other. Add weapons as child GameObjects to the hand, etc.
     
    Croomraider likes this.