Search Unity

Animation not working properly

Discussion in 'Animation' started by Fiffe, Feb 18, 2015.

  1. Fiffe

    Fiffe

    Joined:
    Dec 10, 2014
    Posts:
    19
    I've made my player model in Blender3D - it has one mesh and rigibody. I've created walking and punching animation which both work good when played apart. But whenever I try to walk and punch it cuts the punching animation in half.

    What am I doing wrong, could anybody help me with that? Thanks in advance.
     
  2. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    More info needed.
    Is this in Unity? If so look into avatar mask.
    If in blender possibly posting in a blender forum may give you better chance at feedback.
     
  3. Fiffe

    Fiffe

    Joined:
    Dec 10, 2014
    Posts:
    19
    Yeah. It's all in Unity. The animations work fine in Blender since they are played apart.

    Here's my code for the animations:

    Code (JavaScript):
    1.         //Walking animation
    2.         if(controller.velocity.magnitude >= 0 && (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.D)) && !Input.GetKey(KeyCode.LeftShift))
    3.         {
    4.             animation.Blend("Walk");
    5.             animation["Walk"].wrapMode = WrapMode.Loop;
    6.             animation["Walk"].speed = 1;
    7.         }
    8.  
    9.         //Punching animation
    10.         if((hasMelee == true || hasPickaxe == true || hasAxe == true) && canSwing == true && playerGUI.staminaBarDisplay >= 0.1)
    11.         {
    12.             if(Input.GetMouseButtonDown(0) && player.GetComponent(CraftingController).isBuilding == false)
    13.             {
    14.                 playerGUI.staminaBarDisplay -= 0.1;
    15.                 animation.CrossFade("Punch");
    16.                 isSwinging = true;
    17.                 canSwing = false;    
    18.             }
    19.         }
    The thing is that when I am walking and I click the punching button it tries to punch but cuts the animation in half. He's only raising his hand a little instead of punching. How do I solve this? Is there any specific script for this or do I need to have two halves of body apart - lower and upper?

    Also, where do I find avatar mask? Seems like i don't have any of those on my player model, maybe it's because my model is marked as legacy.
     
  4. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    I don't recall if legacy has any limb masking capability so I defer to others to offer a solution using legacy.
    I don't see why it's only playing half the punch, I'm not a code guy.

    If you switched your rig from legacy to humanoid and used the avatar mask - I think you'd find a solution to your problem.
    This will get you running with avatar mask quickly. That and this.
     
  5. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Fiffe and theANMATOR2b like this.
  6. Fiffe

    Fiffe

    Joined:
    Dec 10, 2014
    Posts:
    19
    Thank you very much!
    If I were to use avatar mask would I need to do the same?
    Also if I created my model with animations in Blender, can I use other type of animation than legacy?
     
  7. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    To use the avatar mask you would need to switch your rig type in Unity from legacy to humanoid.
    Then proceed to setup an avatar and avatar mask as described in the manual. But instead of masking the upper and lower body as with the legacy system, you'd mask the entire body except the arm that is animated.
    So the character would perform the walk animation on his entire body except for the arm that is punching.

    The animation software has no outcome on animation types available in Unity.
     
    Fiffe likes this.
  8. Fiffe

    Fiffe

    Joined:
    Dec 10, 2014
    Posts:
    19
    Okay, thanks for taking your time to help a noob!
    Much appreciated! :)