- Home /
 
 
               Question by 
               Vetm · Mar 13, 2014 at 09:00 PM · 
                androidtouchcontrolstouchscreen  
              
 
              Make an Object follow your touch
I want to make an app where a GameObject snaps to the position of your finger. I searched everywhere and couldn't find any help. I want it to only move right and left and snap to the x position of my finger. I have this code, but it doesn't really work:
 #pragma strict
 
 var speed : float = 1;
 var distance : float = 5;
 function Start () {
 
 }
 
 function Update () { 
     if (Input.touchCount > 0 && Input.GetTouch(0).phase ==     TouchPhase.Moved) {
 
     // Get movement of the finger since last frame
     var touchDeltaPosition:Vector2 = Input.GetTouch(0).deltaPosition;
 
     var touchmove : Vector3 = Vector3(touchDeltaPosition.x, touchDeltaPosition.y, distance);
 
 
     // Move object across XY plane
     transform.position = Camera.main.ScreenToWorldPoint(touchmove);
 }
 }
 
 
               Can anybody give me some code examples of how I could snap the x-cords of the white cube to my touch position?

 
                 
                ss2.png 
                (2.0 kB) 
               
 
              
               Comment
              
 
               
              Set the y value of touch$$anonymous$$ove to zero? 
Your answer
 
             Follow this Question
Related Questions
Three finger tap? 1 Answer
Android Input 1 Answer
How do you map touch to one of the input axes? 1 Answer
Touch Input madness 2 Answers
Problem with touch button (when moved) 2 Answers