# Camera Rotation Script

 0 Hey UnityAnswers,I'm looking for some advice on some code I have. Basically I have 4 cubes, each being a different colour (Red, Blue, Green and Yellow). In the center is an empty gameObject, with the mainCamera parented. When the gameObject rotates, so does the mainCamera. Right now I have input controls to rotate the empty gameObject either left or right, showing each of the cubes.Here is what my scene looks like just for visualization : http://imgur.com/79ibAWhat I'm trying to get is a smooth curve between 90 degree intervals. I don't want it to change like a light switch. I'm not a good programmer, but I'm thinking it involves either for loops, time.Deltatime or transform.Rotate. Let know if you can help me out. The code I'm working on is below. `````` var goodDegs = 30; // degrees per second var badDegs = -30; // degrees per second function Update () { if (Input.GetKeyDown("left")){ for (var n = 0; n < 90; n++) { transform.Rotate(0, goodDegs * Time.deltaTime, 0); } } if (Input.GetKeyDown("right")){ for (var m = 0; m < 90; m++) { transform.Rotate(0, badDegs * Time.deltaTime, 0); } } } ``````or an older version: ``````var rotationPositive = 90; var rotationNegative = -90; function Update () { if (Input.GetKeyDown("left")) { transform.Rotate(Time.deltaTime, rotationPositive, 0); } if (Input.GetKeyDown("right")) { transform.Rotate(Time.deltaTime, rotationNegative, 0); } } `````` more ▼ asked May 20 '11 at 03:26 AM Arthur 1 3 ● 2 ● 2 ● 8 SisterKy 2.4k ● 33 ● 41 ● 59 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 You'll want to set a 'target rotation degrees' OnKeyDown, rather than using a for loop. Anything you do in one frame will all happen in that frame, so you need to spread it across frames. Time.deltaTime is your friend. more ▼ answered May 20 '11 at 04:13 AM DaveA 26.5k ● 151 ● 171 ● 256 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x2994
x2162
x953
x55

asked: May 20 '11 at 03:26 AM

Seen: 3487 times

Last Updated: May 20 '11 at 04:13 AM