2 fingers sprite rotation

Hey guys !

I’m reproducing touch gesture my sprite …
I already did the double tap to zoom in, the pinch and the drag.
I’m currently working on the rotation using two fingers.
I already recognize the fingers, get their position and try to interpret it correctly but so far i didn’t get anything real correct …

Here is what u did :

private void HandleRotation()
    {
        var f1 = new Touch();
        var f2 = new Touch();
        for (var i = 0; i < Input.touchCount; i++)
        {
            var wp = Camera.main.ScreenToWorldPoint(Input.GetTouch(i).position);
            var touchPos = new Vector2(wp.x, wp.y);
            if (collider2D == Physics2D.OverlapPoint(touchPos))
            {
                if (this._fingerIndex == 0)
                {
                    this._fingerIndex += 1;
                    f1 = Input.GetTouch(i);
                }
                else
                {
                    f2 = Input.GetTouch(i);
                }
            }
        }
        if (f1.phase == TouchPhase.Moved || f2.phase == TouchPhase.Moved)
        {
            var turnAngleF1 = Vector2.Angle(f1.position, f1.deltaPosition);
            var turnAngleF2 = Vector2.Angle(f2.position, f2.deltaPosition);
            var turnAngle = (turnAngleF1 + turnAngleF2) / 2;
            Debug.WriteLine(turnAngle);
            transform.Rotate(0, 0, turnAngle * 0.04f);
        }
    }

I figured that when you rotate something with your two fingers, you two fingers does not move at the same speed i then try to ponder the result by adding the two of them and divide the result by 2.

The weird thing is that my turn angle is ALWAYS between 90 and 145, that’s the first thing i don’t really get since my finger are almost not moving.

Second thing i’d like to ask is, how do i figure if my rotation is clockwise or not ?

Thank you for reading and helping.
Bottus.

Untested, but I’m suggesting you replace line 24 - 28 with the following:

var prevPos1 = f1.position - f1.deltaPosition;  // Generate previous frame's finger positions
var prevPos2 = f2.position - f2.deltaPosition;

var prevDir = prevPos2 - prevPos1;      
var currDir = f2.position - f1.position;

var angle = Vector2.Angle(prevDir, currDir);

transform.Rotate(0,0,angle);  // Rotate by the deltaAngle between the two vectors

Note that Vector2.Angle() should be signed. If not you can use Mathf.Atan2() for each of pervDir and currDir and rotate by the difference. Also, rather than generate the previous finger positions, you can just save them from the previous frame.