TileVania Lesson 89 - Ladder Climbing Animation

I am trying to set my animation so that it is like this:

Entry > Idling > Climbing > Idle-Climbing

Where Idle-Climbing is the climbing animation but the loop has turned off (so we are not looking like we are climbing)

I don’t really like having the idle animation playing while we are stationary on the ladder.

I hope that makes sense…

So I created a new “Idle-Climbing” animation and just turned off the loop (I hope this is enough to achieve what I’m after)

But I am not able to get it to enter “idle-Climbing” state. Not really sure why.

Another way I theorized of achieving this goal is to just turn the animation loop off when on the ladder but vertical velocity is 0

Can I get some pointers on how to do this?

My code:

void ClimbLadder()
    {
        if(!myCapsuleCollider.IsTouchingLayers(LayerMask.GetMask("Climbing")))
        {
            myRigidbody.gravityScale = gravityScateAtStart;
            myAnimator.SetBool("isClimbing", false);
            return;
        }

        Vector2 climbVelocity = new Vector2 (myRigidbody.velocity.x, moveInput.y * climbSpeed);
        myRigidbody.velocity = climbVelocity;
        myRigidbody.gravityScale = 0f;

        bool playerHasVerticalSpeed = Mathf.Abs(myRigidbody.velocity.y) > Mathf.Epsilon;
        if (playerHasVerticalSpeed)
        {
            myAnimator.SetBool("isClimbing", playerHasVerticalSpeed);
        }
        else
            myAnimator.SetBool("isIdleClimbing", playerHasVerticalSpeed);
        
    }

Hi,

The states can only transist to a connected state. This means: If the “Idle-Climbing” state is connected with “Climbing”, the current animator state must be “Climbing”. Otherwise, it cannot switch to “Idle-Climbing”.

Furthermore, check the spelling of your bools in your script as well in the animator.

If you cannot find any problems, have you already tried to add Debug.Logs to your code to see what is going on during runtime?


See also:

Here is my animation transitions. I have set the transition action to use “isIdleClimbing” State. When I run the program and I click “isIdleClimbing” check box (like how Rick showed us to test animation) it automatically unclicks and I revert back to regular old idle.

I have set Transition to idle climbing to set isIdleClimbing to true, with “Has Exit Time” set to false and transition duration and exit time both to 0. Same for Transition from Idle-Climbing back to climbing.

I can’t think of a place to put a debug.log statement that would be helpful any ideas?

image

I can’t think of a place to put a debug.log statement that would be helpful any ideas?

I would suggest to check something else first because you wrote “it automatically unclicks and I revert back to regular old idle”. This sounds rather like a problem with the animator settings, unless you ticked the box during runtime. In that case, your code might override the value. What exactly did you do in your project?

Did you define a bool for the “Idling > Climbing” transition? Since the logic flow starts in the “Entry” state and since there is no direct connection between “Idling” and “Idle-Climbing”, make sure that the conditions on the “path” to “Idle-Climbing” are met.

Yes, I have another bool for “isIdleClimbing” and just like Rick showed us I turned off exit time, transition offset and transition duration.

I turned off the loop for the Idle-Climbing animation hoping that it would just stop in the climbing position (e.g. if we are climbing and right hand happens to be up as last frame, I just want it to stay still rather than climbing continuously like it does now)

Exit condition from idle climbing is IsClimbing true.

I think I just may have thought of something as I was typing this out… I’ll need two conditions to be met in order for it to meet Idle climbing right? But which one do I need to have first?

image

And exit condition:

image

Am I getting close? It still doesn’t work…

Also off topic a bit but Rick mentioned you guys offer a pixel art course? Where would I be able to find that?

I’m wondering if you need 2 bools. If you are in the “Climbing” state, I’m wondering if isIdleClimbing being “true” would be sufficient to go to the “Idle-Climbing” state.

You do not want to switch to the “Idle” state just because isClimbing became “false”.

Just an idea: How about swapping the “Climbing” and “Idle-Climbing” state? This way, the “default” state for the player being on the ladder would be “Idle-Climbing”, which is controlled by a trigger instead of a bool.

You’d adjust your code like this:

if (!myCapsuleCollider.IsTouchingLayers(LayerMask.GetMask("Climbing")))
{
    myAnimator.SetTrigger("isClimbing", false);
    myRigidbody.gravityScale = gravityScateAtStart;
    return;
}

// Default behaviour if on ladder
myAnimator.SetTrigger("isIdleClimbing");
myRigidbody.gravityScale = 0f;

Vector2 climbVelocity = new Vector2 (myRigidbody.velocity.x, moveInput.y * climbSpeed);
myRigidbody.velocity = climbVelocity;

// Climbing animation if moving on ladder
bool playerHasVerticalSpeed = Mathf.Abs(myRigidbody.velocity.y) > Mathf.Epsilon;
myAnimator.SetTrigger("isClimbing", playerHasVerticalSpeed);

Of course, you’ll also have to replace the “isIdleClimbing” bool with a trigger in the animator window.

We do have a course for pixel art. See here:

Here is the link with the current active coupon, which is SUMMER.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms