Search Unity

Animations cause character controller to move strangely

Discussion in 'Animation' started by psych int, Feb 12, 2015.

  1. psych int

    psych int

    Joined:
    Feb 12, 2015
    Posts:
    1
    When I attach animations to my game object with a character controller it starts moving very strangely, it seems dependant on the animation that's playing? For example while walking and playing the walking animation the player walks diagonal but if I walk while playing the jumping animation the player will hop a little bit and walk straight. Its like the animations are moving the character controller, I can post gifs if anyone needs more description. I have absolutely no clue and I feel like its something small I have missed, anyone got any ideas?

    Here's my animation/movement code if it helps at all:
    Code (JavaScript):
    1. function Update () {
    2.     vert = Input.GetAxis("Vertical");
    3.     horiz = Input.GetAxis("Horizontal");
    4.  
    5.     if (vert != 0.0 || horiz != 0.0) {//moving
    6.         anime.CrossFade("Walk");
    7.     } else {
    8.         anime.CrossFade("Idle");
    9.     }
    10.  
    11.     velocity = transform.forward*vert*Time.deltaTime*20.0;
    12.     velocity.y = -Time.deltaTime*42.0;
    13.  
    14.     if (cc.isGrounded) {
    15.         if (jump == 0.0 && Input.GetAxis("Jump")) {
    16.             //jump
    17.         }
    18.    
    19.     }
    20.  
    21.     cc.Move(velocity);
    22. }
    EDIT: Never mind solved it, it was caused by a collider on the rig hitting the ground.
     
    Last edited: Feb 12, 2015
    theANMATOR2b likes this.