JUMP animation

13_tv_cud
2d
#1

Hi there.

I finished the course, and was trying to implement more actions to this platformer tutorial.

in this code

    private void Jump()
    {
        if (!myFeet.IsTouchingLayers(LayerMask.GetMask("Ground"))) { return; }

        if (CrossPlatformInputManager.GetButtonDown("Jump"))
        {

            Vector2 jumpVelocityToAdd = new Vector2(0f, jumpSpeed);
            myRigidBody.velocity += jumpVelocityToAdd;
            
        }
    }

I tried, to add a Jump Animation, when he is not touching the ground, (falling or jumping). I added the animation in the Animator, and transitions.

I added this, with no results

    private void Jump()
    {
        if (!myFeet.IsTouchingLayers(LayerMask.GetMask("Ground"))) { return; }

        if (CrossPlatformInputManager.GetButtonDown("Jump"))
        {
            bool playerHasVerticalSpeed = Mathf.Abs(myRigidBody.velocity.y) > Mathf.Epsilon;
            myAnimator.SetBool("Jumping", playerHasVerticalSpeed);
            Vector2 jumpVelocityToAdd = new Vector2(0f, jumpSpeed);
            myRigidBody.velocity += jumpVelocityToAdd;    
        }
    }

Sorry for my broken English.

What could be wrong?

#2

Hi Rolando,

What do you mean by “no result”? What is happening when you are trying to jump?

#3

It means that he is using an Iddle animation when jumping, when I am trying to set a Jumping animation while the player is in the Air.

#4

Did you enable “Has Exit Time”?

#5

Where and how is this done?

#6

Click on the Transition arrow between the states in the Animator.

#7

yes it is enabled

#8

Keep your Animator open while running your game. Then jump and take a look at the Animator state. Which state gets played while your player is jumping?

Make sure that nothing else in your code changes the animator by setting a bool or something else.

#9

I did some Tweaking in the code, and now Jumping animation, is played when I jump. But it stays in the Jumping animation state no matter what I do, (iddle, run, jump).

#10

Is “Loop” enabled for the animation? Maybe no exit time is defined. You somehow need to tell the Animator when to switch the state again. Does your jumping animation have an arrow back to the idle state?

#11

I have to manually click on Exit Time, box on the animator to fix it. But it has to be done for each jump.

#12

Expand the Settings directly below the “Has Exit Time” property. Maybe there is a wrong value that prevents your animation from working correctly.

Also bear in mind that all changes that you do while your game is running get lost. For this reason, make persistent changes when your game is stopped.

#13

Thanks for your help by the way!

#14

Try to set the Exit Time value to 1. This means that the animation will play at least 1 time before the state can be exited.

#15

done and same result :frowning: