Twist to rotate.

Hi Everyone.
I’ve got a little problem.
I want to rotate my cam by using two fingers and twist (like when you rotate a picture in your smartphone)

this is the movement :

i’ve already done the pinch to zoom, here is the code :

private	float		touchDelta = 0.0F;
	private	Vector2		prevDist = new Vector2(0,0);
	private	Vector2		curDist = new Vector2(0,0);
	private	GameObject	obj;
	private	Camera		cam;
	void Start () 
		obj = GameObject.FindGameObjectWithTag("TopCamera");
		cam = obj.GetComponent<Camera>() as Camera;
	void Update () 
		if (Input.touchCount == 2 && Input.GetTouch(0).phase == TouchPhase.Moved && Input.GetTouch(1).phase == TouchPhase.Moved && Event.current.type == EventType.mouseDrag) 
			curDist = Input.GetTouch(0).position - Input.GetTouch(1).position;
			prevDist = ((Input.GetTouch(0).position - Input.GetTouch(0).deltaPosition) - (Input.GetTouch(1).position - Input.GetTouch(1).deltaPosition));
			touchDelta = curDist.magnitude - prevDist.magnitude;
			if ((touchDelta <= 0))
					cam.fieldOfView = Mathf.Clamp(cam.fieldOfView + 1.5f, 10, 60);
			else if ((touchDelta > 0))
					cam.fieldOfView = Mathf.Clamp(cam.fieldOfView - 1.5f, 10, 60);

Thanks :wink:

I’m not sure where you are having a problem or what you expect in terms of an answer. What I would try would be to calculate the angle between the two finger positions each frame using Mathf.Atan2(). Then I’d calculate the delta angle each frame and rotate the camera based on the delta. I belive Mathf.DeltaAngle() handles the 0/360 boundry. Untested:

var v2 = Input.GetTouch(0).position - Input.GetTouch(1).position;
var newAngle = Mathf.Atan2(v2.y, v2.x);
var deltaAngle = Mathf.DeltaAngle(newAngle, oldAngle);
oldAngle = newAngle;

I’m sorry I don’t have any answer, but I did a code for zooming, too. What I did was just setting the Camera FoV to the distance of the 2 fingers (Vector2.distance). That made my code really short.