rotate 90 degrees unity code example

Example 1: transform.rotation - 90 unity

var lookPos = target.position - transform.position; lookPos.y = 0; var rotation = Quaternion.LookRotation(lookPos); rotation *= Quaternion.Euler(0, 90, 0); // this adds a 90 degrees Y rotation var adjustRotation = transform.rotation.y + rotationAdjust; //<- this is wrong! transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);

Example 2: unity rotate object 90 degrees smoothly

IEnumerator RotateMe(Vector3 byAngles, float inTime)      {    var fromAngle = transform.rotation;         var toAngle = Quaternion.Euler(transform.eulerAngles + byAngles);         for(var t = 0f; t < 1; t += Time.deltaTime/inTime) {             transform.rotation = Quaternion.Slerp(fromAngle, toAngle, t);             yield return null;         }     } void Update () {     if(Input.GetKeyDown("e")){     StartCoroutine(RotateMe(Vector3.up * 90, 0.8f));     }     if(Input.GetKeyDown("q")){     StartCoroutine(RotateMe(Vector3.up * -90, 0.8f));     }   } }