I want to make the camera rotate around an object. This is the code ATM.
void Update ()
{
if (Input.GetMouseButtonDown (0)) {
MouseDown = true;
}
if (Input.GetMouseButtonUp (0)) {
MouseDown = false;
}
if (MouseDown==true)
{
if (axes == RotationAxes.MouseXAndY)
{
rotationX = transform.localEulerAngles.y - Input.GetAxis("Mouse X") * sensitivityX;
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
transform.localEulerAngles = new Vector3(rotationY, rotationX, 0);
}
else if (axes == RotationAxes.MouseX)
{
transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
}
else
{
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
transform.localEulerAngles = new Vector3(rotationY, transform.localEulerAngles.y, 0);
}
float X = target.transform.position.x+Mathf.Cos(rotationX)*CameraDistance;
float Z = target.transform.position.z+Mathf.Sin(rotationX)*CameraDistance;
float Y = target.transform.position.y+Mathf.Sin(rotationY)*Z;
this.gameObject.transform.position = new Vector3(X,Y,Z);
}
}
For some reason, it twitches weird when I move the camera. Why? Can somebody help me?