Layered blend trees make it much easier to design complex animation in Mecanim by allowing you to blend on as many parameters as you want, such as speed, direction, and posture. In a recent project, our “Normal Locomotion” blend tree was 3-4 levels deep, with motion fields only at the leaves of the tree.

For idle and walking forward, it even blends on additional parameters Femininity and Swagger to give personality to the characters. (Femininity 0=stereotypical male stance, 1=stereotypical female stance; Swagger 0=plain walk, 1=strutting)

Below are a couple screenshots chopped out of a larger animator controller. The original animator controller has these layers:

  • Base Layer: Whole body animations
  • Arm Layer: Upper body animations
  • Aim Layer: Additive layer to blend aiming in all directions (if using Unity Pro, you could use IK instead)
  • Posture Layer: Crouching, limping, etc.
  • Reaction Layer: Hit reactions
  • The head is controlled by a legacy Animation component because it uses some FaceFX scripts for facial expressions and lipsync.

The top level of the Base Layer looks very simple. It just contains one state machine per stance (Unarmed, Pistol, Rifle, etc.).

When you drill into a stance state machine, it has a blend tree for normal movement, another for movement in cover, and other states for things like vaulting, diving (this is actually a blend tree, too, to support diving at angles), jumping, falling, etc.

The unarmed normal movement blend tree looks like this:

The control method doesn’t use turning-left and turning-right animations. Instead, the player rotates with mouse movement. It still looks good when the player is moving and feels very responsive. When the player is stationary, the Stationary sub-blend tree uses in-place rotate-left and rotate-right animations.

The parameters are:

  • forward: -1 = run backward, +1 = run forward
  • lateral: -1 = run (strafe) left, +1 = run right
  • rotation: -1 = maximum in-place rotation to the left, +1 = max to the right
  • femininity: 0 = male, 1 = female (used for idle and walking forward)
  • swagger: 0 = plain, 1 = lots of swagger (used only for walking forward)

Speed is defined by these range:

  • idle: 0
  • walk: 0.5
  • run: 1.0
  • sprint: 2.0 (only forward)

Instead of using a mess of transitions, we use Animator.CrossFade() heavily to switch between states.

Mecanim’s efficient blend trees made it fairly simple to build up smooth, sophisticated movement that’s easy to control in code.