Rotate Camera in Y axis without visibly changing angle in Z axis
I have a Camera In a square room, with the camera facing straight ahead I can use the arrow keys to rotate around and look at the different walls:
if (Input.GetKey (KeyCode.LeftArrow)) { transform.Rotate (Vector3.up, -turnSpeed * Time.deltaTime); } if (Input.GetKey (KeyCode.RightArrow)) { transform.Rotate (Vector3.up, turnSpeed * Time.deltaTime); }
However I want the Camera to be looking down at an angle of 20 degrees. Setting 20 in the Z axis gets me the desired angle looking at the first wall, but as I rotate around, the camera ends up looking at the ceiling, instead of the back wall. How can I fix this? Is there a way to set the 20,0,0 rotation as the zero or something? or use a parent somehow?
Comment
Best Answer
Answer by toddisarockstar · Jan 04, 2016 at 07:51 PM
with the camera set at the desired angle down, drop it into a new empty gameobject that has its rotations set strait. Use your script on the new parent object to spin that instead!