Search code examples
rotationunity-game-enginequaternions

unity3d. How to get the result of transform.rotate without actually changing the gameobjects transform


In Unity3d I'm entering a transforms position, rotation and scale into a Matrix4x4 in order to draw some gizmos. I'd like the rotation quaternion entered into the matrix to be rotated by a certain amount of euler angles (Angle) This is my attempt, I am making a copy of the transform (temp) , calling rotate() on it and then passing its rotation quaternion into the matrix.

    Transform temp = transform;
    temp.Rotate(new Vector3(0f,0f,Angle));
    Matrix4x4 rotationMatrix = Matrix4x4.TRS(transform.position,temp.rotation,transform.lossyScale);

Unfortunately when i do this it actually rotates the original transform and not just a temporary copy of it as I intended. How can I add a certain amount of euler angle rotation to the quaternion?


Solution

  • I think I've answered this question but it actually doesnt fix my problem...

     Matrix4x4 rotationMatrix = Matrix4x4.TRS(transform.position,transform.rotation*Quaternion.AngleAxis(Angle,Vector3.forward),transform.lossyScale);