How to make the player stay on the ladder when jumping from a distance?

When I try to jump on the ladder from a distance, I fall to the other side. How do I make the player stick to the ladder when jumping on it from a distance? I have tried using physics material (with max friction) on the player as well as the climbing tilemap’s rigidbody/composite collider, but none worked for me. Could you please provide your valuable input?
Here is the gif for your reference.

@ben @Rick_Davidson could you please share your insight into this?

Can you show us what the collider looks like on your ladder and on your player? If you select them both in scene view so that we can see the green outlines, that might give some clues. Specifically, if you have gaps on your ladder collider it might cause issues.

Here is the screenshot showing both the colliders @Rick_Davidson @ben
image

Looks like you need to modify your ladder custom physics shape. This is what mine looks like:

image

1 Like

I am not an expert, but my guess is that, when your player is jumping and moving verticaly
is has velocit in ‘x’ and ‘y’. So it could fall off the ladder becouse of ‘x’ velocity.

Second guess is post above about laddedr physics collider shape.

I’ve been having issues with my character sliding around the ladders. For example, if I stop running underneath a ladder, the character slides, but doesn’t slide if I stop away from a ladder. Jumping onto a ladder and the character slides off half the time.

I’m a bit stumped on the “why” but I suspect the ladders being trigger colliders has something to do with it, since the sliding doesn’t happen on the platforms.

I tried playing with Physics2D materials, but didn’t seem to help. I ended up with possible fix by slowing the X movement down next to ladders using Mathf.Lerp, but I wish I understood why the sliding was happening in the first place.

private void Climb()
{
    bool touchingLadder = collide.IsTouchingLayers(LayerMask.GetMask("Ladders"));
    if (touchingLadder)
    {
        float movement = Input.GetAxis("Vertical");
        bool isClimbing = Mathf.Abs(movement) > Mathf.Epsilon;
        animator.SetBool("Climbing", isClimbing);

        // Possible fix for sliding issues
        float horizontalMovement = rigidBody.velocity.x;
        horizontalMovement = Mathf.Lerp(horizontalMovement, 0, 10f * Time.fixedDeltaTime);

        Vector2 velocity = new Vector2(horizontalMovement, movement * climbSpeed);
        rigidBody.velocity = velocity;
        rigidBody.gravityScale = 0.0f;
    }
    else
    {
        rigidBody.gravityScale = gravityScale;
        animator.SetBool("Climbing", false);
    }
}
1 Like

I just set the X velocity in the Vector2 climbVelocity to 0, so that if you hold up/down (the “Vertical” axis) your horizontal movement snaps to zero and you stick to the ladder.

    Vector2 climbVelocity = new Vector2(0f, controlThrow * climbSpeed);

Then to get off you just have to not hold anything in the “Vertical” axis and jump off.

No, it doesn’t work. the player just sticks to the edge of the ladder, and since x velocity is snapped to zero you cant move the player to middle of ladder, or even jump out of ladder.

@Rick_Davidson @ben could you please help with this issue.

Looks like Nina helped you solve it!

Privacy & Terms