Search Unity

  1. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice
  2. We're running great holiday deals on subscriptions, swag and Asset Store packages! Take a peek at this blog for more information!
    Dismiss Notice
  3. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  4. Unity 2017.2 is now released.
    Dismiss Notice
  5. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  6. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  8. Unity 2017.3 beta is now available for download.
    Dismiss Notice

how do you rotate a vector

Discussion in 'Scripting' started by dansav, Apr 20, 2010.

  1. dansav

    dansav

    Joined:
    Sep 22, 2005
    Posts:
    407
    Is there some unity3d function that will rotate a vector and return a new vector.

    Like vector (5,0,0) rotated 0,180,90 degrees would return
    vector (0,5,0)?



    Thanks,

    Dan
     
  2. tomvds

    tomvds

    Joined:
    Oct 10, 2008
    Posts:
    1,028
    You can multiply the vector with the rotation:

    Code (csharp):
    1. rotatedVector = Quaternion.Euler(0,180,90) * originalVector;
    Note: there is only one allowed order of multiplication. (I believe I got it right as rotation * vector, but I did not test the example).
     
  3. dansav

    dansav

    Joined:
    Sep 22, 2005
    Posts:
    407
    That worked.

    Is there some documentation on quaternions and what you can do with them in terms of vector or quaternion math?

    For example can you multiply quaternions, what is the result?
    A quaternion multiplied by a vector3 what is the result?

    etc..

    Thanks.

    Dan
     
  4. tomvds

    tomvds

    Joined:
    Oct 10, 2008
    Posts:
    1,028
    The Quaternion reference page does discuss the two possible multiplications:
    http://unity3d.com/support/documentation/ScriptReference/Quaternion-operator_multiply.html

    It does, however, do it in the usual brief 'Unity reference style', which may not help you much if you don't already know what a quaternion is ;).
     
  5. ivkoni

    ivkoni

    Joined:
    Jan 26, 2009
    Posts:
    978
    in which case there's always wikipedia
    http://en.wikipedia.org/wiki/Quaternion

    it's a quaternion (representing a composite rotation of the 2 quaternion: rotate by the first quaternion and then by the second. Note multiplication is not commutative, just like the order in which you apply the rotations matters)
    it is a vector (rotated by the quaternion)
     
  6. Cor1312

    Cor1312

    Joined:
    Apr 12, 2010
    Posts:
    34