Search Unity

  1. Get the latest news, tutorials and offers directly to your inbox with our newsletters. Sign up now.
    Dismiss Notice

Set transform rotation over 360 degree

Discussion in 'Scripting' started by Fotal, Dec 25, 2020.

  1. Fotal

    Fotal

    Joined:
    Apr 9, 2019
    Posts:
    34
    Hi, can I set the rotation of the transform like (0,0,680)?
    I need this because then I rotate the game object to (0,0,0) and it would be great if I can set an initial value like (0,0,720) and rotate the object by (0,0,0)


    Code (CSharp):
    1.  
    2. private static void FlipObject(GameObject go, AnimationCurve flipCurve)
    3. {
    4.     var value = flipCurve.Evaluate(Random.value);
    5.    
    6.     var rotation = new Vector3(0, 0, (int)(360f * value));
    7.    
    8.     go.Transform.localEulerAngles = rotation;
    9. }
    10.  
     
  2. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,714
    If you use your own variables to store what the rotation is "supposed" to be, and do your animations based on that, then you can use any numbers you want.

    But I'm pretty sure there's no way to store that information in a Transform's rotation property. Note that the Euler angles aren't even stored explicitly at all; when you set the Euler angles, Unity actually transforms your rotation into a Quaternion and stores that instead. If you ask for the current Euler angles, Unity automatically converts that Quaternion back to angles. So even if all angles are in the 0 - 360 range, you can't guarantee that you'll get back the same set of numbers that you put in.
     
    Fotal likes this.
unityunity