Graphics Reference
In-Depth Information
When the velocity is higher than 0.1, the script relies on _characterState to provide
the correct animation for whatever the player is doing. _characterState refers to the enu-
meration list at the beginning of the script called CharacterState.
The CharacterState animation state held by _characterState is set by the movement
scripts (UpdateDirectionalMovement() and UpdateRotationalMovement() functions), but
the speeds that the animations play at are decided here using the controller.velocity.magni-
tude (the speed at which the character controller is moving) clamped to runMaxAnima-
tionSpeed to keep the number reasonable.
First, the _characterState is checked for running, and the run animation is played at
the speed of runMaxAnimationSpeed:
if(_characterState == CharacterState.Running) {
_animation[walkAnimation.name].speed =
Mathf.Clamp(controller.velocity.magnitude, 0.0f,
runMaxAnimationSpeed);
_animation.CrossFade(walkAnimation.name);
}
The final state is CharacterState.Walking played at the speed of walkMax
AnimationSpeed:
else if(_characterState == CharacterState.Walking) {
_animation[walkAnimation.name].speed =
Mathf.Clamp(controller.velocity.magnitude, 0.0f,
walkMaxAnimationSpeed);
_animation.CrossFade(walkAnimation.name);
}
}
}
}
At the end of the BaseTopDown.cs script, GetSpeed(), GetDirection(), and IsMoving()
are utility functions provided for other scripts to have access to a few of the character's
properties:
public float GetSpeed ()
{
return moveSpeed;
}
public Vector3 GetDirection ()
{
return moveDirection;
}
public bool IsMoving ()
{
return Mathf.Abs(vert) + Mathf.Abs(horz) > 0.5f;
}
}
Search WWH ::




Custom Search