🔸Layers and animator

In this section you will find out how to prepare your animator controller

Step 1 - Add layer references

There're 2 ways to modify procedural animation in runtime:

  • Modifying layers directly

  • Using animator curves

In this step we will focus on how to work with animation layers in runtime. First off, add references to the layers you want to modify based on your project requirements.

Example

FPSController.cs
[SerializeField] [HideInInspector] private LookLayer lookLayer;
[SerializeField] [HideInInspector] private AdsLayer adsLayer;
[SerializeField] [HideInInspector] private SwayLayer swayLayer;
[SerializeField] [HideInInspector] private LocomotionLayer locoLayer;
[SerializeField] [HideInInspector] private SlotLayer slotLayer;

In this case, we've added 5 references to the layers we will later use in the code. To assign the references, we will use this code snippet:

FPSController.cs
private void InitLayers()
{
    InitAnimController(UpdateCameraRotation);
    
    controller = GetComponentInChildren<CharacterController>();
    animator = GetComponentInChildren<Animator>();
    
    // Gettings layer component references
    lookLayer = GetComponentInChildren<LookLayer>();
    adsLayer = GetComponentInChildren<AdsLayer>();
    locoLayer = GetComponentInChildren<LocomotionLayer>();
    swayLayer = GetComponentInChildren<SwayLayer>();
    slotLayer = GetComponentInChildren<SlotLayer>();
}

Here's an example how layers can be used in the main Update loop:

private void SprintPressed()
{
    //... SprintPressed() implementation
    lookLayer.SetLayerAlpha(0.5f);
    adsLayer.SetLayerAlpha(0f);
    locoLayer.SetReadyWeight(0f);
    //... SprintPressed() implementation
}

In this example we call the SetLayerAlpha(float alpha) method, which is a base method for all animation layers. Every animation layer has its own unique method and properties, see more in Animation Layers.

Step 2 - Add animator curves

Control curves

Another important part of the animation setup is Animator Controller and curve parameters. You've probably noticed that all animation layers have this property:

What is this? The property defines the name of the float parameter of your Animator Controller, which will be used to control the weight of the layer.

For example, if the curve value is 1, then the layer is fully applied, if it's 0 - the layer is disabled.

Tip: this is default behavior, Look Layer and Left Hand IK Layer use inverse blending: if the value is 1, the layer is disabled, and if it's 0 - fully applied. These curves are called Masks in the framework.

By default, there're only 2 curves that drive the animation layer blending:

  • SprintWeight - controls the animation system weight. If character is sprinting - the upper body is no longer overidden by the system. Attached to all sprinting motions. Used in Locomotion Layer.

  • MaskLeftHandIK - controls the left hand IK weight. When 1, layer is disabled. Attached to some sprinting animations that do not need left hand IK. Used in Left Hand IK Layer.

  • SprintPoseWeight - controls the sprinting pose. If one - sprint pose is enabled, if 0 - disabled. Used by the Locomotion Layer.

Simply add these curves to your animator:

IK Curves

This is another type of curves, primarily used for procedural animations:

Each curve define movement for every rotation and translation axis. This offset will be applied to the Master IK object (just like weapon sway or recoil). Used in Locomotion Layer.

The demo Animator Controller has a layer for procedural animations:

This is useful when you need to apply some procedural offset to the arms for a specific motion.

For example, let's say we want to move the arms slightly backwards when landing animation is played. We need to only add one single curve IK_T_Z and animate it for our clip:

Last updated