- Home /
Question by
Dinoabunai · Jan 16, 2017 at 07:38 AM ·
cameracamera rotationz-axis
Сamera rotates around Z axis, but I don't want that.
Here is my C# script for camera rotation:
public void CameraRotate(Camera InputCamera, float InputRotationSpeed)
{
if (Input.GetButton("Rotate Camera") == true)
{
float MouseXMovement;
float MouseYMovement;
MouseXMovement = Input.GetAxis("UnityDefaultMouseX");
MouseYMovement = Input.GetAxis("UnityDefaultMouseY");
InputCamera.transform.Rotate(-MouseYMovement * InputRotationSpeed, MouseXMovement * InputRotationSpeed, 0);
}
}
But if I move cursor diagonally, or make circles with it, the camera also turns around Z axis, despite the fact that Z-rotation is set to zero. How I can avoid that?
Sorry for bad english. I hope you'll understand me.
Comment
Best Answer
Answer by Dinoabunai · Jan 17, 2017 at 08:30 PM
Fix it with:
InputCamera.transform.eulerAngles= new Vector3 (InputCamera.transform.eulerAngles.x,InputCamera.transform.eulerAngles.y,0);//That's one line, not two