Graphics Reference
In-Depth Information
myTransform.Rotate(0, horz * rotateSpeed * Time.deltaTime, 0);
curSpeed = moveSpeed * vert;
controller.SimpleMove( myTransform.forward * curSpeed );
// Target direction (the max we want to move, used for
// calculating target speed)
targetDirection= vert * myTransform.forward;
// Smooth the speed based on the current target direction
float curSmooth= speedSmoothing * Time.deltaTime;
// Choose target speed
//* We want to support analog input but make sure you can't
// walk faster diagonally than just forward or sideways
targetSpeed= Mathf.Min(targetDirection.magnitude, 1.0f);
_characterState = CharacterState.Idle;
// decide on animation state and adjust move speed
if (Time.time - runAfterSeconds > walkTimeStart)
{
targetSpeed *= runSpeed;
_characterState = CharacterState.Running;
}
else
{
targetSpeed *= walkSpeed;
_characterState = CharacterState.Walking;
}
moveSpeed = Mathf.Lerp(moveSpeed, targetSpeed, curSmooth);
// Reset walk time start when we slow down
if (moveSpeed < walkSpeed * 0.3f)
walkTimeStart = Time.time;
}
void Update ()
{
if (!canControl)
{
// kill all inputs if not controllable.
Input.ResetInputAxes();
}
UpdateSmoothedMovementDirection();
// ANIMATION sector
if(_animation) {
if(controller.velocity.sqrMagnitude < 0.1f) {
_animation.CrossFade(idleAnimation.name);
}
else
{
if(_characterState == CharacterState.Running) {
_animation[walkAnimation.name].speed =
Mathf.Clamp(controller.velocity.magnitude, 0.0f,
runMaxAnimationSpeed);
Search WWH ::




Custom Search