Skip to content

Instantly share code, notes, and snippets.

@teknoman117
Last active August 29, 2015 14:17
Show Gist options
  • Save teknoman117/e83797ca89bd354539ea to your computer and use it in GitHub Desktop.
Save teknoman117/e83797ca89bd354539ea to your computer and use it in GitHub Desktop.
void Update ()
{
// Movement vector
Vector3 direction = Vector3.zero;
// If the raptor is wandering
if (state == RaptorState.Wandering && controller != null)
{
// Drive the raptor with the controller
direction = controller.inputDirection;
}
// If the raptor is chasing its prey
else if (state == RaptorState.Chasing)
{
// Drive the raptor with the navmeshagent
direction = navigator.desiredVelocity;
}
// If the raptor is in the process of destroying its enemies
else if (state == RaptorState.Attacking)
{
}
// Feed the movement vector into the animation controller
float velocity = direction.magnitude;
float previousVelocity = animationController.GetFloat (inputVelocity);
float newVelocity = Mathf.SmoothDamp (previousVelocity, velocity, ref currentVelocity, velocitySmoothingTime);
animationController.SetFloat (inputVelocity, newVelocity);
// If we are moving, correct the rotation of the character
if (velocity > 0.0f)
{
float rotationTarget = Mathf.Atan2 (direction.x, direction.z) * Mathf.Rad2Deg;
Vector3 orientation = transform.localEulerAngles;
orientation.y = Mathf.SmoothDampAngle (orientation.y, rotationTarget, ref currentAngularVelocity, rotationSmoothingTime);
transform.localEulerAngles = orientation;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment