Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Problem with "jump" animation - 2D

Discussion in '2D' started by dimalev, Jul 31, 2020.

  1. dimalev

    dimalev

    Joined:
    May 25, 2020
    Posts:
    2
    Hello ,

    I have a problem with "jump" animation of my 2d character. when the character in idle or run state it working good. When i press "jump" it looks like the animation "jump" is "stuck".

    upload_2020-7-31_16-13-39.png

    After that the idle and run state stop working.

    transitions:
    Any State to jump:
    upload_2020-7-31_16-29-18.png

    jump to idle:
    upload_2020-7-31_16-29-51.png

    jump to run:
    upload_2020-7-31_16-30-14.png



    the code:

    Code (CSharp):
    1. void Update ()
    2. {
    3. movement = Input.GetAxis ("Horizontal");
    4. animator.SetFloat("Speed", Mathf.Abs(movement));   // working good
    5.  
    6. if (movement > 0f) // move right
    7. {
    8. rigidBody.velocity = new Vector2 (movement * speed, rigidBody.velocity.y);
    9. sp.flipX = false;
    10. }
    11. else if (movement < 0f) // move left
    12. {
    13. rigidBody.velocity = new Vector2 (movement * speed, rigidBody.velocity.y);
    14. sp.flipX = true;
    15. }
    16. else
    17. {
    18. rigidBody.velocity = new Vector2 (0,rigidBody.velocity.y); // jump
    19. }
    20.  
    21. if(Input.GetButtonDown ("Jump"))
    22. {
    23. rigidBody.velocity = new Vector2(rigidBody.velocity.x,jumpSpeed);
    24. animator.SetBool("IsJumping", true);
    25. }
    26. }