Game Development Reference
In-Depth Information
Tip Use Input.GetButton for action events like shooting a weapon or picking up an object. Use
Input.GetAxis for movement.
For keyboard input and joystick input the neutral position equals 0, where each axis has a
value between -1 and 1. A positive button gives a positive value. To see this in action, in the
ZombieLocomotion script add the following lines of code to the Update() function:
var inputValue : float = Input.GetAxis("Vertical");
Debug.Log(inputValue);
Save the script. In the Unity editor Project panel, select the Console tab so you can watch the
Debug.Log output. Enter Play mode. Notice that inputValue is 0. Press and hold the up arrow or
W key and watch it change to 1. Since you set the transition condition to Greater than 0.1 in the
Animator Controller, as soon as the inputValue exceeds 0.1, the transition from the Idle state to the
Walk state is triggered. Release the key, see the inputValue drop to 0, and the transition back to the
Idle state is triggered when it gets below 0.1.
Blend Trees
While transitions are used to switch from one animation state to another, a blend tree incorporates
several animation clips together to blend the motion for a smoother resultant animation movement.
Blend trees are commonly used with walking and running animations. For best results the movement
of the clips to be blended must be similar and take place at the same point in terms of normalized
time. “Normalized time” means that the clips can be of different lengths, where the first frame has a
normalized value of 0.0 and the last frame has a value of 0.99. As long as the left foot touches the
ground at the same normalized time in each clip, say 0.2, and the right foot touches the ground at
the same time, say 0.7, then the clips will blend well.
In the following illustration, a walk animation is compared to a run animation. You know that the
general movement of alternating arm and leg movements are similar, and that it makes sense
that in real time a run loop takes less time than a walk loop, since running is faster than walking.
Normalized time accounts for the speed difference and looks at positions at the same relative point
(represented as a percentage) in the loop cycle. Notice the difference in real time on the bottom left
and normalized time as a percentage on the right (Figure 5-41 ).
 
Search WWH ::




Custom Search