How to add smoothness/easing to this simple Mouse-drag orbit script?

Hello, my coding abilities are limited and I suck at math. I have this script that does pretty much exactly what I want. It orbits the camera around an object. The only problem is that when I release the mouse it just comes to a dead stop. Is there a way to have the motion slow down over time after the mouse is released?

var speed : float = 5.0;

var target : Transform;
 
function Update () {
     if (Input.GetMouseButton(0)) {
         transform.LookAt(target);
         transform.RotateAround(target.position, Vector3.up, Input.GetAxis("Mouse X")*speed);
     }
}
var speed : float = 5.0;
var lastInput : float;
var target : Transform;
 
function Update () {
     if (Input.GetMouseButton(0)) {
         lastInput = Input.GetAxis("MouseX");
     }
     else{
          if (lastInput != 0){
                  lastInput = Mathf.Sign(lastInput) * Mathf.Clamp((Mathf.Abs(lastInput) - 0.05), 0, Mathf.Infinity);
           }
     }
    
     if (lastInput != 0){
         transform.LookAt(target);
        
         transform.RotateAround(target.position, Vector3.up, lastInput * speed);
     }
}

Disclaimer:

  • This is untested, so it might contain errors
  • I don’t use JavaScript, so you may have to properly format some things
  • I’m on my cellphone, so I probably screwed up capitals somewhere

Also, you should learn to adjust for framerate by multiplying units by Time.deltaTime.

Thanks so much!