Search Unity

After Rotation, go back to normal attributes help

Discussion in 'Scripting' started by GrimWare, Apr 6, 2011.

  1. GrimWare

    GrimWare

    Joined:
    Jul 23, 2009
    Posts:
    211
    Hey all. I have a small problem with my entity going back to normal rotation after the player releases the corresponding buttons for the rotation. I'd like the entity to slowly turn back to a 0,0,0 rotation. Could you give me an example of how to do that? Here is my code so far:

    Code (csharp):
    1.  
    2. //this script is to control the Ship
    3. //It uses a traditional WASD control scheme, but W = movement up on Y-Axis
    4. //S = Movement down on Y axis
    5.  
    6.  
    7. function Update() {
    8.     transform.Translate(Time.deltaTime,0,0, Camera.main.transform); //Gives initial thrust
    9.  
    10.     if(Input.GetKey(KeyCode.S)) {
    11.         transform.Translate(0,-.02,0,Camera.main.transform); //slowly move the ship down
    12.         transform.Rotate(0, 0, -.05); //rotate the ship slowly downwards
    13.     }
    14.    
    15.     if(Input.GetKey(KeyCode.W)) {
    16.         transform.Translate(0,.02,0,Camera.main.transform); //slowly move the ship up
    17.         transform.Rotate(0, 0, .05); //rotate the ship upwards
    18.     }
    19.    
    20.         transform.Rotate(0,0,0); //obviously this is where I need the rotateToNormal code.
    21. }
     
  2. fireside

    fireside

    Joined:
    Feb 6, 2011
    Posts:
    203
    Last edited: Apr 6, 2011