Answers for "Why is this rotation not performed as expected?"
http://answers.unity.com/questions/1863575/why-is-this-rotation-not-performed-as-expected.html
The latest answers for the question "Why is this rotation not performed as expected?"Answer by Bunny83
http://answers.unity.com/answers/1863747/view.html
You have the wrong idea of quaternions ^^. A quaternion is always a relative rotation around a single axis. To represent an absolute orientation with a quaternion (which we do with transform.rotation) it has to represent a rotation that brings your coordinate system from the initial orientation to the target rotation. Imagine a simple case where the camera is first looking straight without any rotation. If you rotate the camera 90° to the right it means it's forward axis will change from (0,0,1) to (1,0,0) since the camera is now facing to the right. However which rotation axis gets you there? Exactly, a rotation around the y axis. That would be the axis you have to specify for AngleAxis.
<br>
Most prople make the mistake of still thinking in terms of euler angles. Euler angles are 3 seperate rotations around 3 axis performed one after the other in a particular order. A quaternion represents the combined rotation as one single rotation. The actual rotation axis of the localRotation could be any uninuitive axis since it essentially has to rotate your object within the local space of the parent from the not rotated state to the target rotation with a single rotation axis.
<br>
It's actually an amazing fact that you can rotate toany orientation in space by just a single axis rotation. It's difficult to tell whats your exact goal and why you need this specific setup. Why don't you use LookRotation? Keep in mind that LookRotation also works for local rotations as long as the direction vectors you use are in that local space the rotation lives in. That means the parent coordinate space.
<br>
This question somehow reminds me of [this question we just had about 2 weeks ago][1]. A different case but it also has to do with manipulating the child rotation so it aligns with a worldspace orientation, though with an offset.
[1]: https://answers.unity.com/questions/1861700/quaternion-inverses.htmlThu, 30 Sep 2021 08:45:46 GMTBunny83