You surely thought man the idle animation on the Ladder looks dorky. Well i thought the same so heres a way to freeze an animation i found out. You can do that similiary to the SetBool function of the animator.
So heres the first thing you gotta do.
Go to your Animator and add an Float parameter just like you did with your bools. Let’s call it climbingSpeed or something like that.
Than click on your climbing animation inside of the animator and check the parameter checkmark for speed like shown here. In the dropdown menu set it to climbingSpeed.
Now lets get into our Player Script again.
add
[SerializeField] float climbAnimationSpeed = 1f;
and your ClimbLadder method should look something like this.
void ClimbLadder()
{
bool playerHasVerticalSpeed = Mathf.Abs(myRigidbody.velocity.y) > Mathf.Epsilon;
int ladLayer = LayerMask.GetMask("Climbing");
if(myCollider.IsTouchingLayers((ladLayer)))
{
Vector2 climbVelocity = new Vector2(myRigidbody.velocity.x, moveInput.y * climbSpeed);
myRigidbody.velocity = climbVelocity;
myRigidbody.gravityScale = 0f;
if(playerHasVerticalSpeed)
{
Debug.Log("Climbing");
myAnimator.SetBool("isClimbing", playerHasVerticalSpeed);
myAnimator.SetFloat("climbingSpeed", climbAnimationSpeed);
}
if(!playerHasVerticalSpeed)
{
Debug.Log("Standing on Ladder");
myAnimator.SetFloat("climbingSpeed",0f);
}
}
else
{
Debug.Log("NotClimbing");
myAnimator.SetBool("isClimbing", false);
myRigidbody.gravityScale = standardGravityScale;
}
Check with the Debug look if the states are working.
Now when you’re standing on a ladder the animation freezes.
For more Info on the SetFloat method Unity - Scripting API: Animator.SetFloat