Rotating object through dragging isn´t very smooth.

Hey,

i want to rotate (actually just to the left and right side) an object by swiping over the screen. I have working code already but when i swipe from the left to the right of my screen, the whole movement is kind of lagging.
The object has the following script.
Any help is appreciated… this is driving me crazy.
Thank you for your time!

{
if (Input.touchCount == 0)
{
oldTouchPositions[0] = null;
oldTouchPositions[1] = null;
}
else if (Input.touchCount == 1)
{
if (oldTouchPositions[0] == null || oldTouchPositions[1] != null)
{
oldTouchPositions[0] = Input.GetTouch(0).position;
oldTouchPositions[1] = null;
}
else
{
Debug.Log("Dragging Detected");
Vector2 newTouchPosition = Input.GetTouch(0).position;

float dis = (Vector2.Distance((Vector2)oldTouchPositions[0], newTouchPosition)) / 4;

if (((Vector2)oldTouchPositions[0])[0] < newTouchPosition[0])
{
//Debug.Log("Left"); dunno if correct
vertical = (vertical - velcoidadeDeGiro * dis) % 360;
transform.localRotation = Quaternion.AngleAxis(vertical, Vector3.up);
oldTouchPositions[0] = newTouchPosition;
}
else
{
//Debug.Log("Right");
vertical = (vertical - velcoidadeDeGiro * dis) % 360;
transform.localRotation = Quaternion.AngleAxis(vertical, Vector3.down);
oldTouchPositions[0] = newTouchPosition;
}
}
}```

It’s jerky because you’re storing the new position each time you move the mouse/finger. The best way to do it is by storing the start position when the touch begins and then just updating the ‘distance’ when it moves. In the Unity example here: Unity - Scripting API: Touch.phase you can see that it stores the start value and then just updates the distance each time it moves.