Working with float parameters

In the following recipe, we will show you how to use a float type to switch between clips based on a value that changes continuously, such as the character speed.

Let's assume we have an animation loop for the walking state of the character and another for running. As the character speed increases, it switches between the two states. How can we achieve that? Check out the following recipe to know.

Getting ready

As usual, we follow on from the previous recipe. Have the FBX files named Char@Walk and Char@Run imported and available in the project panel and the Animator window open in the editor.

How to do it...

  1. Go to the Project panel and find the Walk and Run clips of your character. Drag them from the Project panel into the Animator window.
  2. Right-click on the Walk animation and make a transition to Run and another back from Run to Walk.
  3. Create a new parameter, this time a float variable, and name it fSpeed. The following screenshot shows the result you should have so far:
    How to do it...
  4. Click on the transition field to access its properties in the Inspector window.
  5. Set fSpeed as the parameter to blend between Walk and Jump.
  6. Once we set a float variable as the condition for the transition, we are also required to refine the condition itself by setting whether we want the transition to be performed once the value gets larger or smaller than a threshold we set. Set the threshold condition for our float parameter to Greater and set its value to 0.5. This way, the running clip is played as the character speed grows. Please refer to the following screenshot:
    How to do it...
  7. This time, we also flag the Atomic option, because we want this transition to be interrupted whenever the character meets the threshold we set.

How it works...

We added some complexity to the animation system of our character by adding a transition controlled by a float value. We used the float value to blend between the Walk and Run clips, based on the character speed. Assuming an analog control system, with this setup, the character switches between the Walk and Run clips based on the player's input.

..................Content has been hidden....................

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