Copying the rotation matrix of an object.

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.

You can store the rotation of an object by making a copy of Transform.rotation (for a top-level object) or Transform.localRotation (for a child object). Assigning this value back to the appropriate property/field of Transform will set the rotation of the game object back to what it was when you stored the rotation originally. (The same thing can be done with Transform.eulerAngles and Transform.localEulerAngles.)

If this isn't working for you, there must be something else wrong.

Does no one have a suggestion? Please?

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);
}

}

Thanks for the hint. Here it is.

Edit: FINALLY INDENTED IN FOLLOWING POST.