Game Development Reference
In-Depth Information
Beneath it will be an empty list for Motion. Click the + and Add Motion Field three times to add
three motion fields. From the Locomotion Animations folder in the Project panel, drag and drop the
WalkLeftWide, Walk, and WalkRightWide into the fields.
The blue pyramids represent each of the motions, the red mark the parameter value at that particular
point in the graph, and the height of the pyramids at that point show the relative influence or weight of
the child motion in the blend. If you move the slider of the Direction parameter in the Blend Tree Root
Node to 0, the graph in the Inspector shows you that the Walk motion is at its greatest weight while
WalkTurnRight and WalkTurnLeft are at their minimums. WalkTurnLeft is at its maximum at a Direction
parameter value of -1, and WalkTurnRight is at its maximum at a Direction parameter value of 1.
In MonoDevelop, add the following lines of code to the Update() function in the ZombieLocomotion
script:
animator.SetFloat("Direction", Input.GetAxis("Horizontal"));
var directionInputValue : float = Input.GetAxis("Horizontal");
Debug.Log(directionInputValue);
Save the script. In the editor, save the scene. In the Project panel, select the Console tab so you
can see the Speed and Direction parameters change in response to your input. Notice that you
have to have the W or up arrow key pressed for the zombie character to respond to the right or left
arrow keys to turn. This is exactly how you set up the Animator Controller: the WalkTurnRight and
WalkTurnLeft clips are part of the Walk blend tree, so the zombie character must be in the Walk state
in order to turn.
Don't Reinvent the Wheel
The Mecanim Locomotion Starter Kit asset that you imported is a ready-to-go basic animation rig
and controller. While this just scratches the surface of what you can do with Mecanim, now that you
have a solid understanding of how animation clips, animator controllers, and scripts work together,
you can use this and other similar ready-made assets in your projects by customizing them to your
game rather than starting from scratch. Take a closer look at Locomotion now and see what you've
learned.
You should be able to identify the parts of the Locomotion animation state machine depicted in
Figure 5-43 .
 
Search WWH ::




Custom Search