JUMP animation

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?

Hi Rolando,

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

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.

Did you enable “Has Exit Time”?

Where and how is this done?

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

yes it is enabled

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.

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).

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?

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

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.

Thanks for your help by the way!

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.

done and same result :frowning:

@Nina
Bumping this one as shamefully i never finished tilevania

@Marc_Carlyon, thanks for the reminder! :slight_smile:

@Rolando_Peralta, how long is your playerJump animation? And have you already tried to figure out what could be causing the yellow warning message in your console?

image

1 Like

Privacy & Terms