How to do it...

To use additive layers, follow these steps:

  1. Import the character into Unity and place it in a scene.
  2. Go to the Animation tab in the Import Settings.
  3. Find the TiredReference animation and check the Additive Reference Pose option (you can also use the normal Tired animation and specify the frame in the Pose Frame field).
  4. Loop the Idle and Tired animations.
  5. Create a new Animator Controller.
  6. Drag and drop the Idle animation into the controller and make it the Default state.
  7. Find the Layers tab in upper left corner of the Animator window.
  8. Select it and click on the plus button below to add a new layer.
  9. Name the newly created layer Tired.
  10. Click on the Gear icon and set the Blending to Additive, as shown in the following screenshot:
Additive layer settings
  1. Drag and drop the Tired animation to the newly created layer.
  2. Assign the controller to our character.

  1. Create a new script and call it Tired.cs. In this script's Update() function, we set the weight of the Tired layer when player presses the space bar. The Tired layer has the index of 1. We use a helper variable weightTarget to set the new weight to 0 or 1, depending on its current value. This allows us to switch the additive layer on and off every time player presses the space bar. Finally, we interpolate the weight value in time to make the transition more smooth and we set the weight of our additive layer with the SetLayerWeight() function:
        if (Input.GetKeyDown(KeyCode.Space)) 
        { 
            if (weightTarget < 0.5f) 
            { 
                weightTarget = 1f; 
            } 
            else if (weightTarget > 0.5f) 
            { 
                weightTarget = 0f; 
            } 
        } 
        weight = Mathf.Lerp(weight, weightTarget, Time.deltaTime *
        tiredLerpSpeed); 
 
        anim.SetLayerWeight(1, weight); 
  1. Attach the script to the Humanoid character.
  2. Play the game and press the space bar to see the additive animation effect.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.242.157