When standing in front of a ladder, the player character does not jump.
Hello everyone,
I have a tile map with four sorting layers: background, ladder, player and foreground, in that order. Each has a composite 2D collider applied (apart from the player).
I have 2 identifying layers, Ground and Ladder - in that order. The player has a default layer. The player can jump when the ground layer is detected, and can climb when the ladder layer is detected.
However, player can't not jump when standing in front of the ladder despite the ladder's collider being set to 'is trigger'. All layers are in order, and the player does not jump.
My suspicion, is that the velocity is being cancelled out somehow.
Any and all help is appreciated.
private void Climb()
{
if (myCollider2D.IsTouchingLayers(LayerMask.GetMask("Ladder")))
{
float climbInput = playerActionController.Land.Climb.ReadValue<float>();
Vector2 climbVelocity = new Vector2(myRigidBody.velocity.x, climbInput * climbSpeed);
myRigidBody.velocity = climbVelocity;
bool playerHasVerticalSpeed = Mathf.Abs(myRigidBody.velocity.y) > Mathf.Epsilon;
myAnimator.SetBool("Climbing", playerHasVerticalSpeed);
}
else
{
myAnimator.SetBool("Climbing", false);
}
}
private void Jump()
{
if (!myCollider2D.IsTouchingLayers(LayerMask.GetMask("Ground")))
{
return;
}
Vector2 jumpVelocityToAdd = new Vector2(0, jumpSpeed);
myRigidBody.velocity += jumpVelocityToAdd;
}
Why use this method? Just make a raycast, and if your person is hitting it, then the player jumps. I think the raycast method is much easier than this.