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.
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.
Looks like you need to modify your ladder custom physics shape. This is what mine looks 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);
}
}
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.
Looks like Nina helped you solve it!