Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Jump animation clip not playing

Discussion in '2D' started by unity_wzw_guCyjiSkoQ, Jul 7, 2020.

  1. unity_wzw_guCyjiSkoQ

    unity_wzw_guCyjiSkoQ

    Joined:
    Oct 25, 2018
    Posts:
    1
    Hello, i recently follow a tutorial video, and with the same code and parameters i made the King character (the fox is from the tutorial).

    THE PROBLEM is that my character (The King) when jumps it doesn't play the animation and if you look the "IsJumping" CheckBox it disappears very quickly even when the character it's still jumping.


    And Here is the same proyecy whit the Fox Selected to you can see that is playing correctly.


    Why is this happening?
    The only difference is the sprite and animations.
     
  2. DiegoDePalacio

    DiegoDePalacio

    Unity Technologies

    Joined:
    Oct 28, 2009
    Posts:
    506
  3. rubcc95

    rubcc95

    Joined:
    Dec 27, 2019
    Posts:
    222
    The animator is right.
    Check the condition you've setted for IsJumping = true;
    You can see the animation starts at the king but something sets IsJumping = false; close to when he start.
    Search at your script every line where u say IsJumping = false and see when it's called and why, or sent us the code.
     
  4. real_Tepy

    real_Tepy

    Joined:
    Aug 18, 2022
    Posts:
    2
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlayerMovement : MonoBehaviour
    6. {
    7.     public CharacterController2D Controller;
    8.     public Animator animator;
    9.  
    10.  
    11.     float horizontalmove = 0f;
    12.     public float runSpeed=40f;
    13.     bool Jump = false;
    14.     bool Crouch = false;
    15.  
    16.     // Update is called once per frame
    17.     void Update()
    18.     {
    19.         horizontalmove = Input.GetAxisRaw("Horizontal") * runSpeed;
    20.  
    21.         if (Input.GetButtonDown("Jump"))
    22.         {
    23.             Jump = true;
    24.             animator.SetBool("IsJumping", true);
    25.         }
    26.        
    27.         if (Input.GetButtonDown("Crouch"))
    28.         {
    29.             Crouch = true;
    30.         } else if (Input.GetButtonUp("Crouch"))
    31.         {
    32.             Crouch = false;
    33.         }
    34.         animator.SetFloat("Speed", Mathf.Abs(horizontalmove));
    35.  
    36.         {
    37.            
    38.         }
    39.        
    40.     }
    41.  
    42.     public void OnLanding()
    43.     {
    44.         animator.SetBool("IsJumping", false);  
    45.     }
    46.     public void OnCrouching(bool IsCrouching)
    47.     {
    48.         animator.SetBool("IsCrouching", IsCrouching);
    49.     }
    50.  
    51.     private void FixedUpdate()
    52.  
    53.         // Move our character
    54.     {
    55.         Controller.Move(horizontalmove * Time.fixedDeltaTime, Crouch, Jump);
    56.         Jump = false;
    57.     }
    58. }
    i have same issue and that is my code. Can anyone help me?
     
  5. Drnynir

    Drnynir

    Joined:
    Jun 15, 2023
    Posts:
    1
    I had the same code as you and after searching into "CharacterController2D" if found that the "!" at line 57 is the problem. I don't know why it worked with my other game but you can try this with your issue
     
    chronatta likes this.