Player doesn't jump

Hello,

I’m using Unity 2021.3.3f1 and everything used to work smoothly until now when I need to bind Space key to jump sequence.

So my code seems to be triggered correctly to the right place:

void OnJump(InputValue value)

    {

Debug.Log("JUMP!!!");        

        if (!this.myCapsuleCollider.IsTouchingLayers(LayerMask.GetMask("Ground"))) {

            Debug.Log("NOT TOUCHING!!!");

            return;

        }

Debug.Log("touching ground");

        if (value.isPressed) {

            Debug.Log("in");

            this.rigidbody2D.velocity += new Vector2(0f, this.jumpSpeed);

        }

    }

However the jump animation is not happening. Here are some of my screenshoots:



Just to add to that using [up arrow] key does moves the player up but it doesn’t trigger onJump() method. Not sure if that help?

Hi! Welcome to the community!

If I understood correctly, the issue is that the animation isn’t playing, not that the character isn’t jumping, right? If that’s the case, the animation isn’t playing because you aren’t calling it anywhere in your code, you have to tell the animation when to play.

Nope, the character isn’t jumping at all when I press Space, I am afraid.

Try changing your Rigidbody2D variable’s name, there’s a conflict with an inherited class.

Thanks, it worked after restarting Unity. Plus your advice about variable got rid of the warning, so I am double pleased :smiley:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.