How to create different time for rotation ?

Updated on July 3, 2017 in Discussions
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
3 on July 3, 2017
IEnumerator UpdateMovement()
 {
 if (Input.GetKeyDown(KeyCode.W))
 {
 anim.SetBool("isMoving", true);
 Vector3 direction = transform.position - cam.transform.position;
 directionMovement = Vector3.Normalize(direction);
 Quaternion look = Quaternion.LookRotation(direction);
 look.x = 0;
 look.z = 0;
float t = 0f;
 while (t < TimeToRotate)
 {
t += Time.deltaTime / TimeToRotate;
 Debug.Log(t);
 if (t > TimeToRotate)
 {
 t = TimeToRotate;
 }
 transform.rotation = Quaternion.Lerp(transform.rotation, look, t);
 yield return null;
 }
 }else if(Input.GetKeyUp(KeyCode.W))
 {
 anim.SetBool("isMoving", false);
 }
 }

 

So i am trying to create the rotation for a third person character that when the camera look at a direction that character will rotate to that direction using Quaternion.Lerp . But the problem is that everytime if statement check pass it reset the ‘t’ to 0 again so when i try out i actually see my character rotate in a weird way if i try to rotate many direction in a short time . Im pretty new to unity so any help would be great . Thanks 😀

  • Liked by
Reply
2 on July 3, 2017

Before pasting the code here, try first to paste it into notepad so it will loose this weird formatting.

 

on July 3, 2017

Sorry man but i think i fixed the problem and now i dont know how to delete this post

Devoted
on July 3, 2017

No need for deleting 😉

 

Show more replies
  • Liked by
Reply
Cancel