Hey friends, I have a camera that I’m trying to set up with first person perspective using Input.GetAxis(“vertical”) and horizontal. So far it’s kind of working, but the camera appears to be rotating along the z axis (the direction it’s pointed towards) when I look around. What I’d like to do is stop this rotation around the z axis. Here’s my code:
if (zoomedIn)
{
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
if (v < -0.3f)
{
//Debug.Log("look down");
cameraTransform.Rotate(Vector3.right, firstPersonLookSpeed * Time.deltaTime);
}
if (v > 0.3f)
{
//Debug.Log("look up");
cameraTransform.Rotate(Vector3.right, -firstPersonLookSpeed * Time.deltaTime);
}
if (h > -0.3f)
{
//Debug.Log("look right");
cameraTransform.Rotate(controller.transform.up, firstPersonLookSpeed * Time.deltaTime);
}
if (h < 0.3f)
{
//Debug.Log("look left");
cameraTransform.Rotate(controller.transform.up, -firstPersonLookSpeed * Time.deltaTime);
}
}