1. We've introduced thread tags, search within a thread and similar thread search. Read more here.
    Dismiss Notice
  2. We've released our first Timeline Experimental Preview, our new tool for creating cutscenes and more! To check it out click here.
    Dismiss Notice
  3. All Unity Pro perpetual license customers: your special offer to subscribe is ready! Click here.
    Dismiss Notice
  4. Unity 5.5 is now released.
    Dismiss Notice
  5. Check out all the fixes for 5.5 in patch releases 1 & 2.
    Dismiss Notice
  6. Unity 5.6 beta is now available for download.
    Dismiss Notice
  7. Get prepared for the Tizen Mobile App Incentive Program! Read more about the upcoming program here.
    Dismiss Notice
  8. Enter the Microsoft Developer Challenge for a chance to win prizes. Read more about it here.
    Dismiss Notice

Quaternion/Vector 3 rotate/rotation

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

  1. Karmarama

    Karmarama

    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

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

    Karmarama

    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

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