Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void LookAtPosition(Vector3 lookPosition, float speed)
- {
- StartCoroutine(LookAtTransformCorutine(lookPosition, speed));
- }
- public void LookAtPosition(Transform lookPosition, float speed)
- {
- LookAtPosition(lookPosition.position, speed);
- }
- public IEnumerator LookAtTransformCorutine(Vector3 lookPosition, float speed)
- {
- StopLookingAtMouse();
- Vector3 direction = (lookPosition - transform.position).normalized;
- Quaternion targetRotation = transform.rotation * Quaternion.FromToRotation(transform.forward, direction);
- while (Quaternion.Angle(transform.rotation, targetRotation) > 1f)
- {
- transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, speed);
- transform.localRotation = Quaternion.LookRotation(transform.forward);
- yield return new WaitForEndOfFrame();
- }
- }
Add Comment
Please, Sign In to add comment