Rotating around the object

Hello,

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);
        } 
  }

Little bump, Do you guys need more information? Im really struggling here. :smile:

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

using UnityEngine;
using System.Collections;

public class CameraMove : MonoBehaviour {

    public float lookSpeed = 3f;
    public float moveSpeed = 0.5f;

    float rotationX = 0.0f;
    float rotationY = 0.0f;

    void Awake()
    {
        rotationX = transform.rotation.eulerAngles.y;
        rotationY = -transform.rotation.eulerAngles.x;
    }
    void  Update()
    {
        if (Input.GetMouseButton(0) || Input.GetMouseButton(1))
        {
            rotationX += Input.GetAxis("Mouse X") * lookSpeed;
            rotationY += Input.GetAxis("Mouse Y") * lookSpeed;
            rotationY = Mathf.Clamp(rotationY, -90, 90);

            transform.localRotation = Quaternion.AngleAxis(rotationX, Vector3.up);
            transform.localRotation *= Quaternion.AngleAxis(rotationY, Vector3.left);
        }
        transform.position += transform.forward * moveSpeed * Input.GetAxis("Vertical");
        transform.position += transform.right * moveSpeed * Input.GetAxis("Horizontal");
    }
}

Just attach it to your main camera