how can I rotateAround something on the X and Y, but lock the cameras rotation around the Z axis.
so what ends up happening, as I use the mouse to rotate around my camera’s Z rotation value slowly creeps away from 0 and its causing my camera to eventually spin about the Z axis. I want the camera to rotate around the target, but remain locked in the z posisition.
so far im certain it has to do with the line where i define the rightAxis, but I dont know of any other way to do this…
using UnityEngine;
using System.Collections;
public class camera_control : MonoBehaviour {
public Transform target;
private float v;
private float h;
private float w;
private Vector3 rightAxis;
private float hoSensitivity = 2;
private float voSensitivity = 2;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
h = Input.GetAxis("Mouse X");
v = Input.GetAxis("Mouse Y");
//rightAxis = transform.right;
if(Input.GetMouseButtonDown(0)) //0 is left, 1 is right, 2 is middle mouse button
{
//raycast for taget change here or to deselect the target.
}
if(Input.GetMouseButton(1)) //0 is left, 1 is right, 2 is middle mouse button
{
transform.RotateAround(target.position, Vector3.up, h * hoSensitivity); //orbit left/right
rightAxis = transform.right;
transform.RotateAround(target.position, rightAxis, v * voSensitivity); //orbit up/down
}
if(Input.GetMouseButtonUp(2)) //0 is left, 1 is right, 2 is middle mouse button
{
//do something when the mouse button was just released
}
}//end update
}//end script