- Home /
 
               Question by 
               twoface262 · Sep 23, 2013 at 01:24 AM · 
                androidjavascriptiostouch  
              
 
              Make an object move in the direction of touch
Hello, I'm trying to make a custom joystick type of thing for my game and I'm stumped. What I'm doing is making it to where it takes the original coordinates of where you're finger is first placed and getting the offsets of where it's moved and attempting the move the object through that, but it's not working and I can't figure out why. Any answer is greatly appreciated! Thank you!
 var setpos = 0;
 //var oldmpos : Vector2;
 var touchDeltaPosition : Vector2;
 var oldmpose : Vector2;
 function Update () {
 for(var i = 0; i < Input.touchCount;++i){
 if(Input.GetTouch(i).position.x < Screen.width / 2){
 /*
 if( Input.touchCount > 0 && Input.GetTouch(i).phase == TouchPhase.Began && Input.GetTouch(i).phase != TouchPhase.Moved && Input.GetTouch(i).phase != TouchPhase.Ended){
 oldmpose  = Input.GetTouch(i).deltaPosition;
 }else{
 oldmpose.x = 0;
 oldmpose.y = 0;
 }*/
 if(Input.GetTouch(i).phase == TouchPhase.Ended){
 touchDeltaPosition.x = 0;
 touchDeltaPosition.y = 0;
 setpos = 0;
 oldmpose.x = 0;
 oldmpose.y = 0;
 }
 
 if (Input.touchCount > 0 && Input.GetTouch(i).phase == TouchPhase.Moved || Input.GetTouch(i).phase == TouchPhase.Stationary) {            
 if(setpos == 0){
 oldmpose  = Input.GetTouch(i).deltaPosition;
 setpos = 1;
 }
 touchDeltaPosition = Input.GetTouch(i).deltaPosition;
 }else{
 touchDeltaPosition.x = 0;
 touchDeltaPosition.y = 0;
 
 }
 
         
         if(touchDeltaPosition.x > oldmpose.x ){
             transform.Translate(Vector3.right * 0.10);
             }
             if(touchDeltaPosition.y > oldmpose.y  ){
             transform.Translate(Vector3.forward * 0.10);
             }
             if(touchDeltaPosition.y < oldmpose.y ){
             transform.Translate(Vector3.forward * -0.10);
             }
             if(touchDeltaPosition.x < oldmpose.x ){
             transform.Translate(Vector3.right * -0.10);
             }
             
 }
 }
 }
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                