Game Development Reference
In-Depth Information
Declares the boolean variable
inTransition
. This will be set to
true
if the current Animator is in a
transition between animation states and
false
if not.
(8) var inIdle : boolean = state.IsName("Locomotion.Idle");
Declares the boolean variable
inIdle
and set to
true
if the current animation state is the Locomotion
animator's Idle state.
(9) var inTurn : boolean = state.IsName("Locomotion.TurnOnSpot") ||
state.IsName("Locomotion.PlantNTurnLeft") || state.IsName("Locomotion.PlantNTurnRight");
Declares the boolean variable
inTurn
, and set it to
true
if the current animation state is one of
the turning animations. Recall that || is the logic OR operator, so this line declares
inTurn
as a
boolean and sets it to
true
if the name of the current animation state is
Locomotion.TurnOnSpot
OR
Locomotion.PlantNTurnLeft
OR
Locomotion.PlantNTurnRight
.
(10) var inWalkRun : boolean = state.IsName("Locomotion.WalkRun");
Declares the boolean variable
inWalkRun
and set it to
true
if the current animation state is the
Locomotion animator's WalkRun state.
(11) var speedDampTime : float = inIdle ? 0 : m_SpeedDampTime;
var angularSpeedDampTime : float = inWalkRun || inTransition ? m_AnguarSpeedDampTime :
0;
var directionDampTime : float = inTurn || inTransition ? 1000000 : 0;
These statements are used to set the respective damping factors depending on the state of the
animator, whether an animation state or a transition. The syntax here is a very abbreviated form of
a conditional that is not as readable as you've seen so far—remember that the less code, the more
efficient and so the better performance.
The question mark
?
with the subsequent colon is called a
conditional operator
. The condition to
be evaluated comes first, before the question mark. If the condition evaluates to
true
, then the result
of the first expression—after the question mark and before the colon—is the result of the operation.
If
false
, the second expression—after the colon—is the result of the operation.
For example, in the first line of this block of code, the newly declared float variable
speedDampTime
is
set to 0 if
inIdle
is
true
. The character has no speed if it is in the Idle state. If
inIdle
is
false
, the
character is moving so the
speedDampTime
is set to the current value of
m_SpeedDampTime
.
In the second line, the newly declared float variable
angularSpeedDampTime
will be set to the current
value of
m_anguarspeeddsmptime
if the animator is in the WalkRun state OR in transition; otherwise it
evaluates to
false
and it is set to 0.
Similarly, in the third line, the newly declared float variable
directionDampTime
will be set to 1000000
if the animator is in the Turn state OR in transition; otherwise it evaluates to
false
and is set to 0.
(12) var angularSpeed : float = direction / m_DirectionResponseTime;