- Home /
Rotation-projection to new coordinate system
Hello This seems more or less a basic question. I had kinda solved my problem until recently when I discovered some rotations were incorrect. I have a set of objects that need to rotate. After each update call, I receive a new set of Vector3 , all perpendicular to each other that need to be my new coordinate system. At the first frame I have the initial 3 vectors, and while the game continues i need to continually update the objects to rotate (from a pivot point) so they satisfy the new coordinate system.
Is this possible with a basic operation or quaternion logic that I couldn't find so far? Thanks in advance
Answer by jpthek9 · Jan 29, 2015 at 07:18 PM
Vector3 CoordinateDirection = *Any point on the positive z axis of the new coordinate system*;
Vector3 ToRot = Quaternion.lookRotation(CoordinateDirection).eulerAngles + transform.eulerAngles;
transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(ToRot), time.deltaTime * 7);
This'll do it for you. I'm not very familiar with quaternions so I converted them to euler angles for the operations. The last line simply gradually pivots the object to the destinatino.
Although this was not exactly what I had in $$anonymous$$d, it pushed me to the right direction. Using the new z axis to coordinate direction is correct, but loses the rotation on the new z axis itself. Using the new y axis to produce a quaternion for rotation along the new z axis solved that.