Quaternion/Vector 3 rotate/rotation

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

  1. Karmarama

    Karmarama

    New Member

    Joined:
    Jul 11, 2011
    Messages:
    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

    Member

    Joined:
    Dec 17, 2010
    Messages:
    391
  3. Karmarama

    Karmarama

    New Member

    Joined:
    Jul 11, 2011
    Messages:
    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

    Member

    Joined:
    Dec 17, 2010
    Messages:
    391
    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

    New Member

    Joined:
    Jul 11, 2011
    Messages:
    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.