Updated Player Character Animator Contoller for 2.5D Platformer in Unity 2021
Before we cover the ladder code, I’ve updated the PlayerChar_Anim_Controller and transitions for many other states as well.
There are now 15 animation states for the Player’s character including the Entry and Idle states.
We are only tracking 13 states with Boolean flags and could perhaps even narrow this down further, but frankly I’m ready to move on from this.
We don’t track the Entry state or the RunningJump state.
We are tracking the Idle, Walking, Running, Jumping, DoubleJumping, JumpToHanging, HangingIdle, HangingDropping, HangingClimbing, ClimbingUpLadder, ClimbingDownLadder, ClimbingToTop, and LadderDropping.
We’ll go through the settings for each animation state and its associated transitions to other states one at a time.
But first, we’ll cover the animations assigned to each state and their settings.
Rig Import Settings for Humanoid Animations
Before we dive into this individually, always remember to set the Rig as “Humanoid” in your downloaded/imported animation’s settings.
Animations such as those related to climbing require applying the Root Transform Position for either or both the Y and X axis.
Animations such as Idle that interact with those also need to reflect this requirement.
And just to add some confusion, (kidding would do this differently next time), I imported some animations such as the Walk animation with the Root Transform Position which removes the root settings we normally see in the Inspector, such as with the Idle animation above.
The running animation is fairly vanilla, all we need to set here is for it to loop the animation and pose.
Running Jump and Double Jump Animations
There really isn’t anything to do with the Inspector settings for the running jump animation.
Both the running jump and double jump animation states use the Running Jump animation.
Perhaps these could be integrated, but sometimes separation can have its own advantages despite the duplication aspect of this approach.
Like the walking animation, the jumping animation has been imported with Root Motion.
Just to be clear, I would not do this in the future unless the animation failed to work otherwise.
Jump To Hanging Animation
Since our code snaps the player to a location, we don’t want the root transform on the x axis to override this, but the y axis is used here.
Handing Idle Animation
The hanging idle animation was also imported with root motion, but we also need to set it to loop and loop pose.
Hanging Dropping Animation
The hanging dropping animation was also imported with root motion.
Hanging Climbing Animation
Seeing the pattern yet?
Again, I don’t recommend this but it is really a preference.
Climbing Up Ladder Animation
The original width of the ladder was so narrow that the normal climbing ladder animation from mixamo.com had the character’s knee punching through the ladder.
To widen the ladder, we needed to move the character’s hand animations though or they would punch through the ladder.
With Mixamo.com, this is easy, we just adjust the Character Arm Space before downloading the animation to be as wide or wider than the character’s hips / knees.
As far as the settings for the animation, looping and root motion on the Y axis were necessary.
Climbing Down Ladder Animation
Climbing down the ladder uses the same animation as the climbing up the ladder animation state.
It just does so with an animation state speed of -1.5 instead of 1.5.
A negative speed value reverses the animation.
Climbing To Top (Ladder) Animation
The climbing to the top of the ladder animation needs to have root motion for both the x and y axis.
Basing the Y axis on the “Feet” setting gave the best results.
Ladder Dropping Animation
The ladder dropping animation also benefitted from the “Feet” setting.
Idle Animation State and Transitions
All of the animation states should have “Foot IK” enabled to make the feet placement more realistic on the player’s character.
What Do These Animation Transition Settings Mean?
I’ll go over what each setting does in general here rather than covering it for each transition as there are many!
Has Exit Time
This will force a mandatory amount of time for the current animation (in this case Idle) to play before allowing the next state to take over, even when Interruption Source is set as “Next State”.
This is a “normalized value”, meaning that 1 equals the length of the current animation.
If Has Exit Time is enabled and the value for Exit Time is 1, it will force the entire animation to play before moving on to the next animation state.
If Fixed Duration is enabled, the duration of the transition blending from the first animation to the seconds will be in seconds (default to .25 seconds).
If it is disabled, it is in percentage which is easier when you drag this value around directly on the timeline.
The length of duration for one animation to transition to another in either seconds or as a percentage of the length of the first animation.
We can either set the value here or drag the bottom (second to play) animation on the timeline around.
This controls how much overlap or even if a gap of time will occur between each animation.
The “Next State” is the most used setting for this field as it allows the current animation to be cut short (depending on Exit and Duration Time settings) to move onto the next animation.
As we can see above, my idle animation is very long, about 15 seconds.
When the player goes from idle to walking, we don’t want to wait the entire 15 seconds for this animation to finish before starting the walking animation.
So we set this to not have an Exit Time and give it the “Next State” value for the Interruption Source field.
Conditions determine when one the transition should be triggered based on Parameters stored in the editor which can be access from code.
For my animation logic, I’ve chosen to create a Boolean parameter for nearly all of the various animation states and use conditions to trigger the transition when I modify those Boolean values.
In the Idle > Jump transition settings shown above, the Condition is for the “isJumping” Boolean value to equal “true”.
When I change this Boolean value to true through code while in the Idle animation state, it tells Unity I want to transition to the Jump animation.
Walking Animation State and Transitions
Running Animation State and Transitions
Running Jump Animation State and Transitions
Jumping Animation State and Transitions
Double Jumping Animation State and Transitions
Jump to Hanging Animation State and Transitions
Hanging Idle Animation State and Transitions
Hanging Dropping Animation State and Transitions
Hanging Climbing Animation State and Transitions
Climbing Up Ladder Animation State and Transitions
Climbing Down Ladder Animation State and Transitions
Note that the speed value is negative and thus plays the same animation as climbing up the ladder but in reverse.
Climbing to Top Animation State and Transitions
Ladder Dropping Animation State and Transitions
And that should be the last animation state with associated transitions.
In the next article, we’ll go over implementing the climbing ladder mechanic with C#.