Search Unity

  1. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  2. Unity 2017.2 is now released.
    Dismiss Notice
  3. 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
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  6. Unity 2017.3 beta is now available for download.
    Dismiss Notice

Quaternion/Vector 3 rotate/rotation

Discussion in 'Scripting' started by Karmarama, Jul 14, 2012.

  1. Karmarama

    Karmarama

    Joined:
    Jul 11, 2011
    Posts:
    261
    Read the comments in //below

    Code (csharp):
    1.  
    2. var spawnRot : Quaternion;
    3.  
    4. function Start () {
    5. spawnRot = transform.rotation;
    6. }
    7.  
    8. function Update () {
    9. //if something then do following
    10. //narrowed code down to simplify problem
    11. transform.rotation = spawnRot;
    12.  
    13. //would like to slerp/gently rotate transform towards spawnRot - however transform.Rotate is vector3 and cannot
    14. //didn't quite understand quaternion.operator* in docs
    15. //an example would be great ;)
    16. }
    17.  
    Cheers.
     
  2. plzdiekthxbye

    plzdiekthxbye

    Joined:
    Dec 17, 2010
    Posts:
    653
  3. Karmarama

    Karmarama

    Joined:
    Jul 11, 2011
    Posts:
    261
    Tried that before.
    Code (csharp):
    1.  
    2. transform.rotation = Quaternion.Lerp (transform.rotation, spawnRot.rotation, Time.time);
    3.  
    Error:
    Assets/Code/~.js(46,68): BCE0019: 'rotation' is not a member of 'UnityEngine.Quaternion'.
     
  4. plzdiekthxbye

    plzdiekthxbye

    Joined:
    Dec 17, 2010
    Posts:
    653
    spawnRot is already of type Quaternion, you cannot acces .rotation because this is a member of the Transform class. Instead you can use the variable directly to pass it to Quaternion.Lerp. This is basic code understanding, you might want to improve your understanding of object-oriented programming and C# in general.
     
  5. Karmarama

    Karmarama

    Joined:
    Jul 11, 2011
    Posts:
    261
    Code (csharp):
    1.  
    2. transform.rotation = Quaternion.Lerp (transform.rotation, spawnRot, Time.deltaTime * Time.deltaTime);
    3.  
    There we go. Which I swore I tried earlier - perhaps mistyped it. Odd.

    I understand what you mean, to a degree, but I prefer to work with trial and error and generate my own understanding of how everything works - which takes time, and this has added to that.