I have an angled top-down camera with the rotation set at:
X: 25
Y: 185
Z: 0
I just want the Y value to be changed on a “key press” and tried these two methods:
Camera.main.transform.rotation *= Quaternion.Euler(0,1 * Time.deltaTime * this.rotate_speed,0);
or
Camera.main.transform.Rotate(Vector3.up * Time.deltaTime * this.rotate_speed);
In both cases they change all of the rotation values and it ends up creating a big ugly circle. If I simulate my intent in Unity (by changing the Y rotation value manually) this is exactly the effect I’m going for. For whatever reason it doesn’t allow this while the game is playing.
Other items of note, I am implementing this for the iPhone and am pretty clueless when it comes to 3D math (after googling and reading for a bit I still have no comprehension around what a quaternion or a Euler Angle is).
Thanks!
Josh
I have a player set up with an empty object parented to it, then I parent the camera to the empty object. You can put this
var sensitivityY = 5.0;
var minimumY = -60.0;
var maximumY = 60.0;
var rotationY = 0.0;
function Update (){
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = ClampAngle (rotationY, minimumY, maximumY);
yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
transform.localRotation = yQuaternion;
}
static function ClampAngle (angle : float, min : float, max : float) {
if (angle < -360)
angle += 360;
if (angle > 360)
angle -= 360;
return Mathf.Clamp (angle, min, max);
}
on the empty object, the camera will rotate on the y axis between 60 and -60 around the character. I dont know if this is exactly what you are looking for but maybe you can use that script to help with what you are doing.
Thanks for the reply. I gave it a shot, unfortunately the camera rotation just jumps to -0, 0.0999403, 0 and stays there (the y value jumps back and forth rapidly but I can’t see what the values are and it happens so fast the camera doesn’t move). Here is how I tried it (I left out the clamp code just to get something working):
float rotationY = 0F;
rotationY = Time.deltaTime * this.rotate_speed;
Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.up);
Camera.main.transform.rotation = yQuaternion;
Using localRotation gave an error, apparently that doesn’t exist for cameras.
Thanks,
Josh