Search Unity

iTween RotateTo() Direction Question

Discussion in 'Scripting' started by renman3000, Feb 15, 2012.

  1. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    Hi there,
    I have a iTween, rotateTo function question.



    Can I set the direction of the rotation somehow?
     
    Last edited: Feb 15, 2012
  2. Catsoft-Studios

    Catsoft-Studios

    Joined:
    Jan 15, 2011
    Posts:
    703
    Use Vector3.RotateTowards. See the Doc for more info
     
  3. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    Thanks,
    this says it will be rotated on an arc. With out having tested yet, I just want a single axis rotation.


    This still good for that?
     
  4. goat

    goat

    Joined:
    Aug 24, 2009
    Posts:
    5,182
    An arc is a single direction.
     
  5. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    oh right. I suppose so.

    Thanks!
     
  6. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    Sorry but I am having trouble figuring out how to script this.

    Code (csharp):
    1.  
    2.         var currentRotation : Vector3 = activePlayer.transform.rotation;
    3.         var targetRotation : Vector3 = Vector3(0, 0, intRotation); //intRotation is a float.
    4.         activePlayer.transform.rotation = Vector3.RotateTowards(currentRotation, targetRotation, 1.0, 1.0);
    5.  
    line 1 and 2 error:
    Assets/scripts/wpnRealmScript.js(451,71): BCE0022: Cannot convert 'UnityEngine.Quaternion' to 'UnityEngine.Vector3'.
     
  7. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    transform.rotation is a Quaternion not a Vector3. If you need to assign rotation as a Vector3 use transform.eulerAngles.
     
  8. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    Thanks,
    I am still trying to figure it out.


    Code (csharp):
    1.  
    2.         var currentRotation : Quaternion = activeBrain.transform.rotation;
    3.         var targetRotation : Quaternion = Vector3(0, 0, intRotation);
    4.         activeBrain.transform.rotation = Vector3.RotateTowards(currentRotation, targetRotation, 1.0, 1.0);
    5.  
    Code (csharp):
    1.  
    2.         var currentRotation : Vector3 = activeBrain.transform.rotation;
    3.         var targetRotation : Vector3 = Vector3(0, 0, intRotation);
    4.         activeBrain.transform.eulerAngles = Vector3.RotateTowards(currentRotation, targetRotation, 1.0, 1.0);
    5.  
    neither work.
     
  9. srmojuze

    srmojuze

    Joined:
    Mar 18, 2013
    Posts:
    127
    Hi, this works for me. As per http://docs.unity3d.com/ScriptReference/Transform-eulerAngles.html I noted that: "Only use this variable to read and set the angles to absolute values. Don't increment them, as it will fail when the angle exceeds 360 degrees. Use Transform.Rotate instead. Do not set one of the eulerAngles axis separately (eg. eulerAngles.x = 10; ) since this will lead to drift and undesired rotations. When setting them to a new value set them all at once as shown above. Unity will convert the angles to and from the rotation stored in Transform.rotation."

    (my gameObject global x "rotation" starts at 0 and just bounces between 0 and 90)

    Code (CSharp):
    1. iTween.RotateTo(this.gameObject,iTween.Hash(
    2.                                          "x", this.gameObject.transform.eulerAngles.x+90,
    3.                                          "time", 60,
    4.                                          "easetype", "easeInOutSine",
    5.                                          "looptype","pingpong"
    6.                                        ));
     
    filibis likes this.