- Home /
 
 
               Question by 
               oliver-jones · Feb 02, 2011 at 05:28 PM · 
                camerarotatetimeslowly  
              
 
              Rotate Camera In Time
Hello,
I have a camera on my scene, and it rotates left if the user presses Q, and rotates right with E. How do I make the camera rotate slowly? Right now it just snaps 90 degrees, is there a way to make it rotate to 90 degrees but slowly (so you can see the camera rotate -- in other words, animate)
function Update () {
    if(Input.GetKeyDown("q")){
        transform.Rotate(Vector3.up * -90);
    }
    if(Input.GetKeyDown("e")){
        transform.Rotate(Vector3.up * 90);
    }
}
 
              
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by yoyo · Feb 02, 2011 at 05:51 PM
Use the key presses to set your target rotation, not your actual rotation, then lerp towards your target each frame.
Something like this ...
float damping = 2.0f;
float rotate = Mathf.Lerp(transform.localEulerAngles.y, targetRotate, damping * Time.deltaTime);
transform.Rotate(Vector3.up * rotate);
 
              Your answer
 
             Follow this Question
Related Questions
Rotation question 1 Answer
Camera Rotating Around (0, 0, 0) 2 Answers
Change characters direction using camera view 0 Answers
Camera in fixed position which rotates with player. 0 Answers
World of Warcraft Camera 2 0 Answers