private IEnumerator move(Vector3 lastPosition, Vector3 currentPosition, float time) { float elapsedTime = 0; Vector3 targetDir = currentPosition - lastPosition; Quaternion finalRotation = Quaternion.LookRotation(targetDir); while (elapsedTime < time) { transform.position = Vector3.Lerp(lastPosition, currentPosition, (elapsedTime / time)); avatarFigure.transform.rotation = Quaternion.Lerp(avatarFigure.transform.rotation, finalRotation, (elapsedTime / time)); elapsedTime += Time.deltaTime; dist = Vector3.Distance(lastPosition, currentPosition); AvatarAnimationState state = AvatarAnimationState.Idle; if (dist > 4) { state = AvatarAnimationState.Run; } else { state = AvatarAnimationState.Walk; } if (state != animationState) { animationState = state; OnAnimationStateChanged.Invoke(animationState); } yield return(new WaitForEndOfFrame()); } animationState = AvatarAnimationState.Idle; OnAnimationStateChanged.Invoke(animationState); // avatarFigure.transform.rotation = finalRotation; }
private IEnumerator move(Vector3 lastPosition, Vector3 currentPosition, float time) { float elapsedTime = 0; Vector3 targetDir = currentPosition - lastPosition; Quaternion finalRotation = Quaternion.LookRotation(targetDir); while (elapsedTime < time) { transform.position = Vector3.Lerp(lastPosition, currentPosition, (elapsedTime / time)); avatarFigure.transform.rotation = Quaternion.Lerp(avatarFigure.transform.rotation, finalRotation, (elapsedTime / time)); elapsedTime += Time.deltaTime; dist = Vector3.Distance(lastPosition, currentPosition); ///////////////////////////////////////////////// if (dist <= 3) { girl.GetComponent <Animation>().Play("Idle"); man.GetComponent <Animation>().Play("Idle"); } else if (dist > 3.5f && dist <= 100f) { girl.GetComponent <Animation>().Play("Walk"); man.GetComponent <Animation>().Play("Walk"); } else if (dist > 100f) { girl.GetComponent <Animation>().Play("Run"); man.GetComponent <Animation>().Play("Run"); } CheckSpeed.speedShow = dist; ////////////////////////////////////////// AvatarAnimationState state = AvatarAnimationState.Idle; if (dist > 4) { state = AvatarAnimationState.Run; } else { state = AvatarAnimationState.Walk; } if (state != animationState) { animationState = state; OnAnimationStateChanged.Invoke(animationState); } yield return(new WaitForEndOfFrame()); } animationState = AvatarAnimationState.Idle; OnAnimationStateChanged.Invoke(animationState); // avatarFigure.transform.rotation = finalRotation; }