I would like to make a copy of the rotation matrix of an object so that I could call GameObject.Transform.LookAt() so it will look at me (this part works), then restore its rotation back to where it had been before the LookAt call. I've tried copying gameObject.transform.localEulerAngles and copying the Transform.rotation quaternion (well, I could only copy the x, y, z and w parameters anyway). Neither worked. I also tried copying the original up and forward properties and that didn't work either. In all cases, the character ends up misaligned to the world (actually, come to remember, in this last case the character was aligned but no longer facing forward). How could I do that? Thanks in advance.
EDIT: The code is simple: function Update () { if (calculateDistance(GameObject.Find("Main Camera"), this.gameObject) > 4f) { if (rotationQuat.y != 10001) { //this.transform.LookAt(originalForward, originalUp); //this.gameObject.transform.rotation = rotationQuat; //this.gameObject.transform.localEulerAngles = rotation; this.gameObject.transform.rotation = rotationQuat; //rotation.y = 10001; rotationQuat.y = 10001; } this.animation.Play ("Walks"); //this.gameObject.transform.Translate(0, 0, .02f); } else { this.animation.CrossFade ("Attacks"); //rotationQuat = new Quaternion(this.gameObject.transform.rotation.x, this.gameObject.transform.rotation.y, this.gameObject.transform.rotation.z, this.gameObject.transform.rotation.w); //rotationQuat.SetLookRotation(this.gameObject.transform.rotation.GetLookRotation()); rotationQuat = this.gameObject.transform.rotation; //rotation = this.gameObject.transform.localEulerAngles; this.transform.LookAt(GameObject.Find("Main Camera").transform); } }
I appreciate your help.