How to do it...

To use additional animations for a better-looking transition, follow these steps:

  1. First, follow all the points from the Using root motion to steer a character recipe to have a working character driven by root motion animations.
  2. In the Animation Import Settings of the character, find your additional ToIdle animation. You may need to add it as a new clip by clicking on the plus button in the Clips section (Animations tab) and choosing the ToIdle animation as the source.
  1. Check the Bake Into Pose option for Root Transform Rotation and Root Transform Position (Y) in the ToIdle animation.
  2. Open the Animator Controller (this should be the same controller as in the previous recipe), add another float parameter, and call it ToIdle.
  3. Go back to the Animation Import Settings and find the WalkForward animation.
  4. In its import settings, go down to the Curves section, unfold it, and click on the plus icon to add a new Animation Curve.
  5. Name it ToIdle (its name should match exactly the parameter we created in the Animator Controller in step 4). Click on the curve (it's a flat green line at the moment) to open the Curve Editor. Curves are described by float values on the vertical axis and normalized animation time on the horizontal axis.
  6. Create a square-shaped curve with its maximum value equal to 1 and its minimum value equal to 0 (point 1 in the following screenshot). You can add curve control points by clicking on the curve. You can select points by clicking on them. You can remove points with the Delete key. To adjust the handles and interpolation types of a point, right-click on it. To set a square curve, choose Both Tangents | Constant. You can save a Curve Preset for later use by clicking on the small gear icon in the lower left corner of the Curve Editor (see point 2 in the following screenshot). When you scrub through the timeline (point 3 in the following screenshot), you can see where your curve starts in the normalized animation time (point 4 in the following screenshot):
Animation Curve and the Curve Editor
  1. In our example, the Idle animation has its left foot in front and our ToIdle animation starts with its right foot in front. During the animation, the character makes a small step to go back to the proper Idle pose with its left foot in front. In the WalkForward animation settings, try to set the curve value to 1, on the passing pose, when the right foot passes the left foot (and will be in front of the character few frames later).
  2. Save the curve as a Curve Preset and add it to the WalkLeft and WalkRight animations. Set their curves names to ToIdle as well.
  3. Go to the Animator Controller.
  4. Add the ToIdle animation and create new state transitions:
    • Steering | ToIdle with two conditions, the Speed parameter less than 0.5 and the ToIdle parameter set to greater than 0.5. Has Exit Time should be set to false and Transition Duration should be set to 0.2 seconds.
    • ToIdle | Idle with no conditions, Has Exit Time set to true, and Transition Duration set to 0.2 seconds.
  5. Alter the Steering | Idle transition by adding a second condition to it: the ToIdle parameter set to less than 0.5. See the following screenshot:
Animator Controller using an additional ToIdle transition animation
  1. Start the game and try walking and stopping the character in different time of the walk animation. You should see that the character plays the ToIdle animation to prevent foot sliding in the most visible case of the walk pose being a mirrored idle pose.
..................Content has been hidden....................

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