private void moveToPosition()
{
// Set the rotation of the model to point in the direction of the target
Quaternion newRotation = Quaternion.LookRotation (targetPosition - transform.position);
newRotation.x = 0f;
newRotation.z = 0f;
transform.rotation = Quaternion.Slerp (transform.rotation, newRotation, Time.deltaTime * 10);
// Tell the controller to move in the straight-line direction
// between the current position and the waypoint
Vector3 dir = (path.vectorPath [currentWaypoint] - transform.position).normalized;
dir = dir * GetMovementSpeed();
characterController.SimpleMove (dir);
// Have we reached the waypoint in the path?
if (Vector3.Distance (transform.position, path.vectorPath [currentWaypoint]) < nextWaypointDistance) {
// Advance to the next waypoint
currentWaypoint++;
// If we have reached the last waypoint in the path,
// then we need to stop the walking animation
if (path.vectorPath.Count == currentWaypoint)
{
CancelPath();
}
}
}