Search Unity

Odd Animation/Animator Networking Issues

Discussion in 'Scripting' started by Foestar, Aug 14, 2018.

  1. Foestar

    Foestar

    Joined:
    Aug 12, 2013
    Posts:
    350
    So I'm not sure if this is an Animator issue or a coding issue. But I have my player spawn in when they host a game or join a game using UNet. Works fine so far, but now I started adding my animations and I'm thinking either I'm doing it wrong or something about my code is off.

    When the player joins I have their animator get grabbed by a private animator variable like so.
    Code (CSharp):
    1. [SerializeField]
    2.     private Animator playerAnim;
    3.  
    4.  
    5.     void Start()
    6.     {
    7.         playerAnim = this.GetComponent<Animator>();
    8.     }
    So I created the private animator and linked it directly from the player that spawned in. This much works, as in the inspector it shows the correct animators (ie: "player1 animator", "player2 animator", etc.)

    Then I check to see if the keys are down and change a bool within the animator for the running character. An example is the W key like so:

    Code (CSharp):
    1. void Update()
    2.     {
    3.         if (Input.GetKey(KeyCode.W))
    4.         {
    5.             playerAnim.SetBool("isRunning", true);
    6.         }
    7.         else
    8.         {
    9.             playerAnim.SetBool("isRunning", false);
    10.         }
    11.     }
    So here is where the weird stuff happens. The characters Idle animation is playing, so that much works as it's the default starting animation. But when I move the current players animator bool isRunning DOES change and the animator window shows a transition between the animations Idle and Running, but the animation itself doesn't work. Some how it doesn't transfer to the character model.

    Even more odd, is if I click on the animator when starting the game it doesn't change when I hit play and do the actions. It wont change until I click on that player himself and his animator (which is how it should work as each player has their own animator). But if I don't click the player and select the animator directly in the project folder and change it myself (since the code doesn't change that one) it will force the change in the player's model.

    Not sure if I explained this well, but this seems like I'm doing it wrong or something.
     
  2. mjzx

    mjzx

    Joined:
    Aug 18, 2013
    Posts:
    114
    Hmmm, did you check to make sure your player's animation rig is set to 'Humanoid' ? If it is, then I wouldn't have a clue as to what could be causing this.

    Also, like you said, when you click on Animator in the project view, it shouldn't be showing actions in the Animator window, but when you click on the player itself, it should. I'm pretty sure this is perfectly normal, as this happens to me too. This is most likely intended, because if it was the same, and you had multiple objects using that controller, then they wouldn't be able to be independently animated, they would all be the same. (Someone correct me if I'm wrong.)

    Good luck ;)
     
  3. Foestar

    Foestar

    Joined:
    Aug 12, 2013
    Posts:
    350
    Hmmmm, the animation is working now. I read your post, got home turned on the pc and went to double check the players rig setup for humanoid, which it was, then hit play and it's working. I didn't change anything, only checked to ensure it was in fact humanoid and it was.

    I'm not entirely sure what was happening, but perhaps it didn't properly load the animation? I did make changes to the fbx file itself in 3DS Max for the players hand placement. So I'm thinking something hadn't updated between the export and my quick coding.

    Everything's working great now!
     
    Last edited: Aug 14, 2018
  4. mjzx

    mjzx

    Joined:
    Aug 18, 2013
    Posts:
    114
    Hmm, strange. It probably was an import issue.
    Nice to see you got it working though !
     
  5. Foestar

    Foestar

    Joined:
    Aug 12, 2013
    Posts:
    350
    EDIT: So I rephrased this post to be a bit more clear, but here goes.

    I'm getting a new awkward animation issue where the strafing animations are pulled to face down the X axis as though they're facing forward with the running motion. This is extremely odd to me, mainly because in 3DS Max they're facing down corresponding Y axis with his head facing down the X axis so as to look as though he's running left/right while still facing forward.

    The issue is for some reason in Unity the legs keep getting pulled to face down the X axis so it always looks like he's running forward instead of the correction side to side motion.

    If you look in the preview window in Unity at the bottom right the players head is rotated to look down the Y axis and his legs the X. So it's inverting my players body orientation with X and Y axis and I'm not sure why. Am I missing a simple step? o_O
     
    Last edited: Aug 18, 2018
  6. Foestar

    Foestar

    Joined:
    Aug 12, 2013
    Posts:
    350
    Here's a video showing the issue.