Forum begins after the advertisement:


[Part 2] Jump issue

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #12070
    alp erkan
    Participant

    I implemented the jump stuff and everything works well but there is this one problem. When I don’t hold down the jump button and instead just push and release very quickly, character makes a full jump instead of making a very short one. I think the editor doesn’t update fast enough so it doesn’t see that I released my jump button and it doesn’t set the vertical velocity to 0. How can I solve this issue?

    #12071
    Terence
    Keymaster

    Hi alp Erkan,

    You will have to add a new line of code in your jumping script to check if 1) you are jumping and 2) the jump button is not being held down, and then set the vertical velocity to zero.

    EDIT: See below for the code.

    #12124
    burbza
    Participant

    Terence,

    Can you please provide the code for fixing this problem ? Especially setting the vertical velocity to zero.

    #12125
    Terence
    Keymaster

    Hi burbza,

    I haven’t tested this, but you can try this and see if it works. I’ve highlighted the change to the code below:

        void Jump()
        {
            if(!Input.GetButtonUp("Jump") && rb.velocity.y > 0)
            {
                rb.velocity = new Vector2(rb.velocity.x, 0);
    
                pState.jumping = false;
            }
    
            if (!pState.jumping)
            {
                if (jumpBufferCounter > 0 && coyoteTimeCounter > 0)
                {
                    rb.velocity = new Vector3(rb.velocity.x, jumpForce);
    
                    pState.jumping = true;
                }
                else if(!Grounded() && airJumpCounter < maxAirJumps && Input.GetButtonDown("Jump"))
                {
                    pState.jumping = true;
    
                    airJumpCounter++;
    
                    rb.velocity = new Vector3(rb.velocity.x, jumpForce);
                }
            }
    
            anim.SetBool("Jumping", !Grounded());
        }

    Update: I missed the ! in the code highlighted in green above in my earlier edit of the post.

    #12133
    burbza
    Participant

    Now the player can’t jump at all when i’m holding the jumping button. I can do only very small jumps and only if i press the jump button very fast.

    #12138
    Terence
    Keymaster

    Hi burbza, I updated the code above (in the green highlight). Let me know if the new code works for you.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: