Drag rotate object

Hi,

I have an issue with this script:

void Update () 
	{
		//if(!resetting)
		//{
		if (Input.GetMouseButton(0))
		{
			mouseHit = Camera.main.ScreenPointToRay(Input.mousePosition);
			
			if (Physics.Raycast(mouseHit, out hit)) 
			{				
				mousePos = Input.mousePosition;
				currPoint = (hit.point - transform.position).normalized; //direction
				
				if(mousePos != oldMousePos)  // to make sure it will not keep moving when the mouse is stationary
				{
					axisToRotateAround = Vector3.Cross(prevPoint, currPoint); //axis to rotate around
											
					angleToUse = Vector3.Dot(currPoint,prevPoint) ; // angle between the two vectors
								
					//transform.rotation = Quaternion.AngleAxis(angleToUse , axisToRotateAround) * transform.rotation;
					
					transform.RotateAround (axisToRotateAround,angleToUse * 8.0f * Time.deltaTime);
			
					prevPoint = currPoint;
					oldMousePos = mousePos;
				}
			}
		}

If I make the rotation fast then I get a jitter/stutter when dragging http://www.artzfx.com/cnc/3dplayer02.html

If I slow it down then no jitter/stutter but the user has to do too much dragging around http://www.artzfx.com/cnc/3dplayer01.html

I changed from transform.rotation to transform.RotateAround() and added the multiplier of 8.0f which I have been playing around with. Also I have tried using FixedUpdate instead (plus lots of other code I have discarded).

Any help would be very welcome as I am looking for a smooth drag with no jitter.

The object in the example has a box collider and no rigidbody

thanks

This is basically what I use for rotating my camera around an object and it seems to work well for me:

x += deltaPos.x * xSpeed;
			
y -= deltaPos.y * ySpeed;
			
// stops the player from flipping the camera upside-down and disorienting themself
y = Mathf.Clamp(y, yMinLimit, yMaxLimit);
				   
rotation = Quaternion.Euler(y, x, 0);
			
distanceVector.z = -distance;
position = rotation * distanceVector + target.position;

Thanks Elrick.

I was approaching it by rotating the object rather than the camera so if there are multiple objects in scene each can be rotated individually.

Currently I get a stutter when I ‘speed up’ the rotation and its this bit thats bugging me as I can’t see why its happening other than the its kind of flipping between current and previous position in the Update but I can’t see that whilst debugging it.

thanks again and if anyone can suggest something for this I would appreciate it.

Effectively its similar to the preview window in Unity