Climb up animation in Unity
Objective: Climb up the ledge from a grabbing position
This article is all about using some simple tricks to manipulate the player position once the climbing animation has completed. As you might know I am not using root animation for this project and that comes with a drawback when making a mechanic like the ledge grab and climbing up.
In the video above you can see the player looks like they are climbing but it is only the animation that is moving and it leaves the player behind. If you look closely you can see the capsule that is the player collider is not moving while the climbing animation is playing. This is where the small trick comes in. Once the climb animation is completed I am moving the player position to a hand selected position on the platform.
As with the previous articles on animations I have added in the climb animation to the animator and the transitions.
On the climb up animation I have added in a animation behaviour that runs once the animation has exited.
In this new behaviour script we do not have access to add any new variables.
In the above screenshot you can see an override method that will run once the animation has exited, in my case it is the climbing animation and once it has finished it will move to idle.
As I said above we do not have access to add new variables outside the methods, so how do you communicate with the player? Well, we have access to the animator that is attached to the player. So, I find the playercontroller component which is on the parent object. I then run the new ClimbUpComplete method.
In the climb up method I am setting the player position to the hand chosen position for the specific ledge we’re on(I’ll show this in a minute) and setting the ledge grab bool to false. I then need to re-enable the character controller so that they can move.
In the GrabbingLedge method from a previous article I have now added in a LedgeGrab object. This means that no matter which ledge the player is on, when they stand up they will appear in the standing position that is set for that ledge.
Here, you can see that I am now passing in the object that has the ledgegrab script attached to the GrabbingLedge method.
The last part to set up, is the position that the player needs to stand on once the animation is finished.