Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Vector3 rotation

Discussion in 'Scripting' started by svenskefan, Dec 11, 2009.

  1. svenskefan

    svenskefan

    Joined:
    Nov 26, 2008
    Posts:
    282
    On a popular subject, I know.
    This time around I can´t simplify things by using transofrm rotation since I am actually trying to rotate the gravity Vector.

    I have been trying to do

    rotQuat=Quaternion.Euler(x_Rot,0,z_Rot);

    Physics.gravity*=rotQuat;

    And it kind of works, althoug i get a compilation error
    "opeator "*" cannot be applied to operands of type UnityEngine.Vector3 and UnityEngine.Quaternion

    what would be a decent way to rotate gravity, similar to
    targetcontrol.transform.Rotate (z_move, 0, y_move) for GameObjects?

    TIA
     
  2. tomvds

    tomvds

    Joined:
    Oct 10, 2008
    Posts:
    1,028
    You got it right. However, the *= operator is not implemented. Quat-Vec multiplication only works when the Quat is the left-hand-side of the operator:
    Code (csharp):
    1. Physics.gravity=rotQuat*Physics.gravity;
     
  3. svenskefan

    svenskefan

    Joined:
    Nov 26, 2008
    Posts:
    282
    Grrrrrrreat!
    thanks