Forum begins after the advertisement:

 


[Part 2] Double jump sometimes gets consumed after dash

Home Forums Video Game Tutorial Series Creating a Metroidvania in Unity [Part 2] Double jump sometimes gets consumed after dash

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #19236
    Sissi Zhang
    Level 2
    Participant
    Helpful?
    Up
    0
    ::

    Hi! I have followed your tutorial and have progressed to the 6th episode, where I ran into a weird bug.

    I have implemented both double jump and dash mechanics. The issue is that when I perform jump, dash (in mid-air), jump (this one should be the double jump), sometimes the double jump is consumed and does not trigger. However, this does not always happen, and the exact condition to trigger this bug I’m not sure. I’ve uploaded a short video demonstrating the behavior (https://youtu.be/ciLxAlnUs-U).

    When the bug is triggered, it does not seem like it’s caused by input timing, because even if I press the jump key more than one time, the player still won’t perform the double jump. I tried to serialize the jump counter, and noticed that this value does not increase when this happens (can be seen in the video), which means it’s not a logical error. Based on this, I suspect the issue is caused by the dash implementation, but I’m not sure what exactly is causing this issue.

    Could you point me where to look for and how to debug for this? Any help would be appreciated.

    #19237
    Terence
    Level 31
    Keymaster
    Helpful?
    Up
    0
    ::

    Admittedly, our jump function is not coded in the best way — the code has a lot of room for improvement. But this is the condition you want to pay attention to:

    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());
    }

    Specifically, after jumping and dashing, look at what the airJumpCounter and maxAirJump values are. Does your dash affect the value of these 2 variables?

    To see these properties, while playing in editor, you can select your player GameObject and see its properties in the Inspector. Look at these 2 properties and see what values are there, and whether the values meet the conditions listed in the highlighted section.

    Hope this helps.

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

Go to Login Page →


Advertisement below: