title: Dragging Camera based on Touch (Unity)
body: <p>In my game, I want the camera to move based on the user swiping their finger. My issue is that when someone removes their finger from the screen, and places it down again, the camera jumps to a new position... I am guessing it has to do with the coordinates, I say this because if I click somewhere far from where I removed my finger from the screen, the camera jumps. Here is the code:</p>
  
  <pre><code> var speed : int = 1;
  
   var lastPoint : Vector2; //make this private if you want to.
  
   function Update()
   {
  
       var offset : float; //offset of the touch from last frame     
  
       if(Input.touches.Length  0)//make sure we have a touch in the first place
       {
  
            var evt : Touch = Input.touches[0];   //setting up touch events so we can get fancy.
            if(evt.phase == TouchPhase.Began)    //this is the first frame the screen has been touched for, simply save the point.
            {
                 lastPoint == evt.position;
            }
            else if(evt.phase == TouchPhase.Moved
            {
                offset = evt.position.x - lastPoint.x ;//take the difference
  
                //I'm going to use Transform.Rotate because it's handy dandy
  
                transform.Rotate(0,offset * speed,0);
  
                //save the new "lastPoint"
  
                lastPoint = evt.position;
           }
           else if(evt.phase == TouchPhase.Ended)
           {
               //If you want the object to drift after you spin it you can make a function to go here.
               //To do this, take the speed of the rotation and continue to rotate all while subtracting off of the speed.
               //I would use the Transform.Rotate function on this too.
               //If you need me to I could write this function too.
  
           }
       }
   }
  </code></pre>
  
  <p>What is the solution to have the camera resume, and not jump once someone puts their finger down again?</p>
  
  <p>I am also willing to redo it, if there is a better solution/more efficient method of solving the issue.. </p>
  
  <p>Thanks a lot!</p>