Search Unity

Rotating objects in time.

Discussion in 'Editor & General Support' started by Juan, Jul 2, 2009.

  1. Juan

    Juan

    Joined:
    May 21, 2009
    Posts:
    142
    So that's the problem now.

    I have an object, and i want ot rotate it from 0 degrees to 90 degrees (it's a door) when i click a mouse button.

    My problem is that i cannot get the object rotating smoothly within time, i mean, i tried with Time.deltatime, also tried with Quaternion.Slerp, but no solution, i'm on this by 2 hours now.

    Help please.


    Thanks.
     
  2. Juan

    Juan

    Joined:
    May 21, 2009
    Posts:
    142
    no one with anything?

    pleaaaaaaaaaaaaase.

    It's not rotate the object ALL the time, only when i change a variable from 0 to 1 and the angle must be from 0 to 90 degrees.

    Thanks.
     
  3. Screenhog

    Screenhog

    Joined:
    Jul 2, 2009
    Posts:
    498
    If I understand your problem correctly, there's probably many ways to accomplish this... but here's what I did with a pinball flipper, and it should be the same concept.

    First I had this code in GlobalVar.js:

    Code (csharp):
    1.  
    2. static var flipperRot = 90;
    3. static var rotSteps = 10;
    4.  
    Then, this code was in a different .js file:

    Code (csharp):
    1.  
    2. private var leftShiftDown = 0;
    3.  
    4. function Update () {
    5.     if (Input.GetAxis("LeftFlipper") == 1) {
    6.         if (leftShiftDown < GlobalVar.rotSteps) {
    7.             transform.Rotate(Vector3(0,0,-1)*(GlobalVar.flipperRot/GlobalVar.rotSteps));
    8.             leftShiftDown++;
    9.         }
    10.     }
    11.     if (Input.GetAxis("LeftFlipper") == 0) {
    12.         if (leftShiftDown > 0) {
    13.             transform.Rotate(Vector3(0,0,1)*(GlobalVar.flipperRot/GlobalVar.rotSteps));
    14.             leftShiftDown--;
    15.         }
    16.     }
    17. }
    The second .js file looked at the first one for its variables, and then, whenever the left Shift button was pressed, the flipper would rotate up to a certain point and then stop. When the left Shift button was released, the GetAxis variable had changed, so the flipper would go back to its original state.

    Sorry... I didn't comment the code at the time. But hopefully this makes sense.
     
  4. Juan

    Juan

    Joined:
    May 21, 2009
    Posts:
    142
    I think you helped me a lot :) i must study this a bit, but i think this can solve my problem.

    Thanks! :D