- Home /
Changing Z-Axis of camera
Hey, I'll post little part of my mouselook script (Basically mouselookplus, but little bit simpler):
function Update(){
Limiter();
rotationZ = 180; // 180 is just for testing, but it's not working with any value
transform.localRotation = Quaternion.AngleAxis (rotationZ, Vector3.forward);
if(Axis == Axes.MouseX){
rotationX += Input.GetAxis("Mouse X") * sensitivity;
transform.localRotation = Quaternion.AngleAxis (rotationX, Vector3.up);
}
if(Axis == Axes.MouseY){
rotationY += Input.GetAxis("Mouse Y") * sensitivity;
transform.localRotation = Quaternion.AngleAxis (rotationY, Vector3.left);
}
}
Why rotationZ isnt rotating Z axis? It works if I disable rotationX, but how I can get all 3 working at the same time?
Thanks really much, I got it working, but one problem.. How I can make smoother mouse movement? Now it's really cheesy, not good at all :/.
EDIT: I fixed it! I just had to make 2 scripts, one for camera and one for player model. Thanks so much!
Answer by AlucardJay · Jan 06, 2013 at 11:57 AM
Quaternion.AngleAxis only calculates one angle, and resets the others. For example, from the API : http://docs.unity3d.com/Documentation/ScriptReference/Quaternion.AngleAxis.html
transform.rotation = Quaternion.AngleAxis(30, Vector3.up);
this will set the rotations thus :
x = 0;
y = 30;
z = 0;
What you need to do is construct a quaternion that holds the values for x and z, then apply that to transform.rotation
var rotAngle : Quaternion = Quaternion.Euler( rotationY, rotationX, 0.0 );
transform.rotation = rotAngle;