# How to make a Smooth speed reduction after MouseDrag?

I’m new.
It is necessary to gradually reduce the speed of rotation of the object, after I stopped rotating it with the mouse.
I used Lerp, Boolean variables, it all works. But in the end nothing works.

``````public class cloudRotate : MonoBehaviour
{
public float rotationSpeed;
public int mouseMultiply;
public float lerpRate;

bool mouseControll;
bool lerpNeed;

float X; //mouse drag speed
float t; // lerp duration

private void Start()
{
rotationSpeed = 0.2f;
mouseMultiply = 30;
lerpRate = 1f;

mouseControll = false;
lerpNeed = false;
}

private void Update()
{

if ( mouseControll == false ) {
Debug.Log(rotationSpeed);

if (lerpNeed) {
rotationSpeed = Mathf.Lerp(X, rotationSpeed, t);
t += lerpRate * Time.deltaTime;
Debug.Log(t);
}

if (t > 1.0f)
{
lerpNeed = false;
t = 0.0f;
}

}

transform.Rotate(0, rotationSpeed, 0);

}

void OnMouseDrag()
{
mouseControll = true;
X = Input.GetAxis("Mouse X") * rotationSpeed * mouseMultiply;
transform.Rotate(new Vector3(0, -1, 0), X);
}

private void OnMouseUp()
{
mouseControll = false;
lerpNeed = true;
t = 0;
}

}
``````

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

``````public class cloudRotate : MonoBehaviour
{
public float sensitivity = 0.2f;
public float acceleration = 0.2f;
public float rotationSpeed = 20.0f;

private float accelerationX;
private float mouseX;

void Update()
{
if (Input.GetMouseButtonDown(0))
{
mouseX = Input.mousePosition.x;
}
transform.Rotate(new Vector3(0, accelerationX - rotationSpeed * Time.deltaTime, 0), Space.World);
accelerationX = Mathf.Lerp(accelerationX, 0, Time.deltaTime / acceleration);
if (Input.GetMouseButton(0))
{
float deltaX = mouseX - Input.mousePosition.x;
accelerationX = deltaX * sensitivity;
mouseX = Input.mousePosition.x;
}
}
}
``````

Thank you!
Now I will try to understand how it works.
There’s a problem here:
When you click the mouse set some value rotation and get a jump