- Home /
How can I rotate a camera useing 2 touches?
I want to rotate a camera by useing 2 fingers.
Here is my code: using UnityEngine; using System.Collections;
 public class RotateCamera : MonoBehaviour {
 
     public GameObject camera;
     public float rotationSpeed;
 
 
     // Update is called once per frame
     void Update () {
         if(Input.touchCount == 2)
         {
 
             Touch touchZero = Input.GetTouch(0);
             Touch touchOne = Input.GetTouch(1);
 
 
             Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;
             Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition;
 
             float angle = Vector2.Angle(touchOne.position-touchZero.position, touchOnePrevPos - touchZeroPrevPos) * rotationSpeed;
             Vector3 r = camera.transform.eulerAngles;
             r.z += angle;
             camera.transform.eulerAngles = r;
         }
     }
 }
 
The problem is, that the resulting angle is always positive. What can I use to know which side it is rotating? What can I use as a reference to compare the vectors?
               Comment
              
 
               
              I know Vector3.Angle() returns an unsigned angle, but I though that Vector2.Angle() returned a signed angle. If not, you can use $$anonymous$$athf.Atan2() to get a signed angle between Vector3.right and any 2D vector.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                