- Home /
 
Air jumping animation help
Hi guys, I haven't done unity in a while, so i forgot a lot stuff for coding. I was following the tutorial "2D Character Controllers" and things gone okay. The only problem i have is that when my player jump, the jumping animation didn't play.
         target = Camera.main.ScreenToWorldPoint (Input.mousePosition);
         if ((grounded || !doubleJump) && Input.GetMouseButtonDown (0)) 
         {
             if (target.x <= transform.position.x) {
                 anim.SetBool ("Ground", false);
                 GetComponent<Rigidbody2D> ().AddForce (new Vector2 (speed, jumpForce));
                 target.z = transform.position.z;
                 transform.localScale = new Vector3 (-1, 1, 1);
                 rb2D.velocity = Vector3.left;
 
               I changed few thing when i follow the tutorial. I want my character to move AND jump using Input.mousePosition. My plan was to make my player constantly air jumping while dodging obstacles. that works okay but the only thing i need help with is
how do I play jumping animation every time my character jump?
can you post a picture of your animation controller?
From Any State to swim what is the name of the transition used?
Answer by Dream_in_code · Aug 27, 2016 at 02:28 PM
Rigidbody2D myRB;
Animator myanim;
bool grounded = false;
void Start()
{
     myRB = GetComponent<Rigidbody2D>();
     myanim = GetComponent<Animator>();
 
               }
void FixedUpdate() {
     grounded = Physics2D.OverlapCircle(groundcheck.position, groundcheckRadius, groundLayer);
     myanim.SetFloat("vSpeed", myRB.velocity.y);
     myanim.SetBool("Ground", grounded);
   
 
               if (grounded && Input.GetMouseButtonDown (0))
{
         myanim.SetBool("Ground", grounded);  
         myRB.velocity = new Vector2(speed, jumpForce);
     }
 
              thanks! it works 90%, the only thing bugs me a little is that the animation didn't play as soon as i move. it took like maybe 0.5 second later to play the animation. but other than that, Thank you so much
Glad it worked :) for the delay part you can check settings of your Transitions. Check if the fixed duration or exit time has not been set correctly.
Your answer
 
             
