Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Reset Rotations

Discussion in 'Scripting' started by nickavv, Sep 21, 2007.

  1. nickavv

    nickavv

    Joined:
    Aug 2, 2006
    Posts:
    1,801
    Code (csharp):
    1. static var finished = false;
    2. static var started = false;
    3.  
    4. function Start () {
    5.     started = true;
    6.     LevelUp.minSpeed = 0.0;
    7.     LevelUp.maxSpeed = 0.0;
    8. }
    9.  
    10. function Update () {
    11.     if (transform.position.z > 4) {
    12.         StopSpinning();
    13.     }
    14. }
    15.  
    16. function StopSpinning () {
    17.     Destroy (constantForce);
    18.     Destroy (rigidbody);
    19.     transform.rotation.x = 270;
    20.     transform.rotation.y = 0;
    21.     yield WaitForSeconds (1.4);
    22.     LevelUp.minSpeed = LevelUp.newmin;
    23.     LevelUp.maxSpeed = LevelUp.newmax;
    24.     finished = true;
    25.     started = false;
    26.     Destroy(gameObject);
    27. }
    In the function StopSpinning, you can clearly see that I set the X to 270 and the Y to 0 (the Z is always 0), but instead of appearing correctly it is set to (0, 180, 180), which makes this particular GO completely invisible. If I pause and change it to the correct rotation it immediately snaps back when I unpause. What is going on here?
     
  2. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    Possibly change the euler angles intead of rotation.

    Code (csharp):
    1. transform.localEulerAngles.x = 270;
    2. transform. localEulerAngles.y = 0;
     
  3. nickavv

    nickavv

    Joined:
    Aug 2, 2006
    Posts:
    1,801
    Another thanks Dan. :D