Inertia rotation

I’m having a problem with inertia rotation of an object, in that I have a script which when attached to an object works however what I need if for the object to slow don to an eventual stop which I can’t seem to get done. I’ve attached the script which I am working with any help would be appreciated.

Thanks

public float rotationSpeed = 2.5f;
	public float lerpSpeed = 0.1f;
	
	private Vector3 speed;
	private Vector3 avgSpeed;
	public bool dragging = false;
	private Vector3 targetSpeedX;
	public bool touchFound;
	public float touchTimer;
	
	void OnMouseDown() 
	{
		touchFound = true;
	}

	void OnMouseUp()
	{
		touchFound = false;
	}

	void Update() 
	{
		if(touchFound == true)
		{
			touchTimer += Time.deltaTime;
		}
		else if(touchFound == false)
		{
			touchTimer = 0f;
		}

		if(touchTimer >= 0.3f)
		{
			dragging = true;
		}
		else if(touchTimer <= 0f)
		{
			dragging = false;
		}

		if(dragging)
		{
			speed = new Vector3(-Input.GetAxis ("Mouse X"), Input.GetAxis("Mouse Y"), 0);
			avgSpeed = Vector3.Lerp(avgSpeed,speed,Time.deltaTime);
		} 
		else
		{
			if(dragging)
			{
				speed = avgSpeed;
				dragging = false;
			}
			var i = Time.deltaTime * lerpSpeed;
			speed = Vector3.Lerp( speed, Vector3.zero, i);
		}
		
		transform.Rotate(Vector3.up, speed.x * rotationSpeed, Space.World);
		transform.Rotate(Vector3.left, -speed.y * rotationSpeed, Space.World);
	}

Ok I kind of have it working, if anybody else wishes to use this all you have to do is over time after the initial mouse/finger rotation has started is make the rotationspeed number go down until it reaches 0 and then lock it at 0 until another finger swipe is started.

1 Like