Right now when I click right mouse button, it will instantly rotate to that position. But what I would Like to do is take the current mouse position, and add that to the current camera rotation. So it will not jump, when I click. But Instead when I click right mouse button, it will start to rotate from where ever i click from.
private void LateUpdate()
{
if (Input.GetMouseButtonDown(1))
{
x += Input.GetAxis("Mouse X") * xSpeed * distance * 0.02f;
y -= Input.GetAxis("Mouse Y") * ySpeed * distance * 0.02f;
y = ClampAngle(y, yMinLimit, yMaxLimit);
Quaternion rotation = Quaternion.Euler(y, x, 0);
Vector3 position = rotation * negDistance + target.transform.position;
cam.transform.rotation = rotation;
}else if (Input.GetMouseButtonUp(1))
{
target.transform.Rotate(0, horizontal, 0);
}
}
Here is a script I wrote that will spin the camera around the Y axis as you move the mouse left/right. Pan the camera up and down (rotate about X-Axis) as you move it up and down.
It also physically moves the camera forwards/back and strafes left/right using WASD
CameraMove script