Search Unity

Wrong Animation

Discussion in 'Scripting' started by JaimieVos, Sep 21, 2017.

  1. JaimieVos

    JaimieVos

    Joined:
    Jun 21, 2015
    Posts:
    193
    I have an Idle, Walk and Jump animation. Walking and idling does work but when I jump it goes to the jump animation but for too long. When my player get back on the ground again it stays in the jump animation for 1 more second.

    Screens:



    Here ^^ it waits 1 second and then normal again:

     
  2. RoMax92

    RoMax92

    Joined:
    May 29, 2017
    Posts:
    135
    Try to change some values in the animator, like duration, velocity, exit time, or other stuff
     
    ZetroEUW likes this.
  3. JaimieVos

    JaimieVos

    Joined:
    Jun 21, 2015
    Posts:
    193
    Duration isn't gonna work because when I jump to a higher ground it will still be wrong. Disabling exit time doesnt work.
     
  4. RoMax92

    RoMax92

    Joined:
    May 29, 2017
    Posts:
    135
    Can i see some code?
     
  5. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,187
    How are you currently controlling what animation plays? Are you detecting when the player lands and swapping back to a different animation?
     
  6. Rob21894

    Rob21894

    Joined:
    Nov 21, 2013
    Posts:
    309
    You could make sure all transitions in the animator have Exit Time disabled, Then in your script, detect when the player lands and set the jump to false by something like
    Code (CSharp):
    1. animator.SetBool("Jump",falsE);
     
  7. JaimieVos

    JaimieVos

    Joined:
    Jun 21, 2015
    Posts:
    193
    Code (csharp):
    1.  
    2.     void Jump() {
    3.  
    4.         if (Input.GetKeyDown (KeyCode.Space)) {
    5.             if (grounded) {
    6.                 rigid.AddForce (Vector2.up * jumpPower);
    7.                 anim.SetBool ("Jump", true);
    8.                 grounded = false;
    9.             }
    10.         }
    11.     }
    12.  
    13.     void OnCollisionEnter2D(Collision2D collider) {
    14.         if(collider.gameObject.CompareTag("Ground")) {
    15.             anim.SetBool ("Jump", false);
    16.             grounded = true;
    17.         }
    18.     }
    19.  
     
  8. RoMax92

    RoMax92

    Joined:
    May 29, 2017
    Posts:
    135
    I think it maybe let the animation finish before pass to the next one... It's some parameter in the animation for sure