0
\$\begingroup\$
Quaternion objectRotation = Quaternion.identity;
Quaternion rotation = Quaternion.AngleAxis(angle, Vector3.forward);
objectRotation *= rotation;

gameObject.transform.rotation *= objectRotation;

here angle = -90

But the gameobject isn't rotating as desired, when I replaced

gameObject.transform.rotation *= objectRotation;

with

 gameObject.transform.Rotate (0,0,angle);

Then the gameobject rotated -90 degree, dont understand why the Quaternion part isn't working? It rotated 90 degrees

\$\endgroup\$
  • 1
    \$\begingroup\$ I can't reproduce your problem, the first snippet works fine. My object rotates from (0, 0, 0) to (0, 0, -90) \$\endgroup\$ – Hellium Oct 13 '17 at 7:28
  • \$\begingroup\$ @Hellium Do the both method behave the same way? \$\endgroup\$ – MrRobot9 Oct 13 '17 at 9:27
  • 1
    \$\begingroup\$ Yes, the quaternion rotation and Rotate call gave me the same result. \$\endgroup\$ – Hellium Oct 13 '17 at 9:41
  • 1
    \$\begingroup\$ Supposing angle = -90 ; Quaternion method : (0, 0, 0) => (0, 0, -90) ; (10, 20, 30) => (10, 20, -60) ; Rotate method : (0, 0, 0) => (0, 0, -90) ; (10, 20, 30) => (10, 20, -60) (same result) \$\endgroup\$ – Hellium Oct 13 '17 at 10:30
  • 2
    \$\begingroup\$ Maybe, you should deal with localRotation instead of rotation, especially if you have parents already rotated. \$\endgroup\$ – Hellium Oct 13 '17 at 10:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.