How to Jump While Climbing a Ladder in 2D

So I’ve been working for hours trying to get this to work. Basically, I’m controlling a 2d character’s velocity and while on a ladder, their velocity is the yInput * climbingSpeed else; it’s just the y velocity. Jumping is being handled by setting the y velocity to “jumpForce”. The issue with everything is that the character doesn’t jump when I’m either touch the ladder nor actively climbing.

This is where the normal movement and climbing movement is done.
P.S. ApplyMovement() is called in FixedUpdate()

void ApplyMovement()
    {
        float crouch = (isCrouching) ? crouchMultiplier : 1f;
        float run = 1;
        //float run = (Input.GetKey(KeyCode.LeftControl)) ? runMultiplier : 1f;  //Sprinting Value
       //checks if touching ladder
        if (Physics2D.OverlapCircle(groundCheck.position, GroundedRadius, whatIsClimbable)) { isClimbing = true; rb.gravityScale = 0f; }
        else { isClimbing = false; rb.gravityScale = 3.5f; }

        //Adding Force Horizontally (no Slope detected) and when not jumping nor pillarJumping
        if (Physics2D.OverlapCircle(groundCheck.position, GroundedRadius, whatIsGround) && !isOnSlope &&/* !isJumping && */!isPillarJumping)
        {
            //jumpForce = 1f;
            isJumping = false;
            //performedJump = false;
            movement.Set(movement.x + groundedspeed * xInput * crouch * run * slowMultiplier,
                isClimbing ? (yInput * climbingSpeed) : rb.velocity.y);
            movement.x *= (1 - groundedDamp);
           
        }
        //Adding Force towards Slope's direction (when Slope detected)
        /*else if (Physics2D.OverlapCircle(groundCheck.position, GroundedRadius, whatIsGround) && isOnSlope && canWalkOnSlope && !isJumping && !isPillarJumping)
        *{
        *    movement.Set(movement.x + groundedspeed * slopeNormalPerp.x * -xInput * crouch * run * slowMultiplier,
        *        movement.y + groundedspeed * slopeNormalPerp.y * -xInput * crouch * run * slowMultiplier);
        *    movement *= (1 - groundedDamp);
        *    rb.velocity = movement;
        }*/
        //Adding Force Horizontally and Mid-air Speed Multiplier
        else {//gets here when holding jump before release
            movement.Set(movement.x + midairspeed * xInput * crouch * run * slowMultiplier,
                isClimbing ? (yInput * climbingSpeed) : rb.velocity.y);
            movement.x *= (1 - midairDamp);
        }
        rb.velocity = movement;
    }

This is where the values for jumping are done when the player presses jump

    public void pressedJump(InputAction.CallbackContext obj)
    {
        jumpForce = 17f;
        ActivateJumpValues();
    }
public void ActivateJumpValues()//InputAction.CallbackContext obj)
    {
        if (!performedJump)
        {
            CatchMissedTimer = CatchMissedDuration;
            performedJump = true;
            //isJumping = false;
        }
    }

This is where the jumping is actually done when the player releases jump

public void releasedJump(InputAction.CallbackContext obj)
    {
        //jumpForce = 1f;
        DoJump();
    }
public void DoJump()//InputAction.CallbackContext obj)
    {
        if(!isPillarJumping) rb.velocity = new Vector2(rb.velocity.x, Mathf.Clamp(rb.velocity.y, -Mathf.Infinity, jumpReleaseClamp));
        //CatchMissedTimer : the timer of the space input to stay registered (to register a jump when player is accidently pressing space before landing
        //CoyoteTimer : the timer of grounded to stay registered (to avoid player pressed jump after walking off a cliff)
        if (CatchMissedTimer > 0) CatchMissedTimer -= Time.deltaTime;
        if (CatchMissedTimer > 0 && CoyoteTimer > 0 && !isPillarJumping)
        {
            isJumping = true;
            //CatchMissedTimer = CatchMissedDuration;
            CoyoteTimer = 0f;
            rb.velocity = new Vector2(rb.velocity.x, jumpForce);
            performedJump = false;
        }
    }

Some of the problem comes from the contradictions between jumping and laddering.

Usually ladders are auto-mount: eg, you get close enough (collider or trigger or rect overlap) and press up or down, the game infers you are on the ladder and should be acting in a ladder-y way. Some games require you to hit a button to “connect” to the ladder.

When you jump from a ladder, technically you are still overlapping the ladder, so you need some kind of inhibition from considering reattaching to that ladder, assuming you would auto-ladder. Like what if you jump straight up? Does it instantly reattach at the next rung? Or wait until you’re descending then reattach? Or stay permanently detached?

What if you have air-control of your jump and change your mind to come back to to the ladder? It should attach, right? Or should it only attach to a ladder when you start by walking onto it from a platform?

Every one of these are going to be substantially-different state diagrams.

You’re welcome to look at my ladder code… you can NOT jump off the ladder (you can step off it though), but you CAN jump onto the ladder. Look for the DemoClimbLadder2D scene here:

proximity_buttons is presently hosted at these locations:

https://bitbucket.org/kurtdekker/proximity_buttons

https://github.com/kurtdekker/proximity_buttons

The thing about it is that the game is meant to be a fast paced platformer. So the intended way that I want the ladder to work is instantly be able to climb when you’re touching it, if you jump while on the ladder, you go a bit higher up on it; if you are at the very top of the ladder, you do a normal jump.

I solved the issue, I used a short-hand if/else statement in the “movement.set” function so that if isClimbing=true the player would move based on jumpForce+movement.x else, they would just move normally.