- Home /
 
Manipulating Variables With Multi-Touch
I want to move multiple instances of the same object with separate touch inputs. To be more specific, I have an object on the left and an object on the right. I want to move the object on the left with my left index finger, and the object on the right with my right index finger. I have this working to a degree, but I cannot figure out how to manipulate one object without interfering with the other. The script as it stands recognizes each touch as a separate touch, but I am unsure how to manipulate the movement variables for each touch event. Here is the script as it stands :
 var verticalLimit : float = 1.2;
 var scrollDistanceY : float;
 
 function FixedUpdate () {   
 
  for (var i = 0; i < iPhoneInput.touchCount; ++i) 
  {
      var hit : RaycastHit;
      var ray = Camera.main.ScreenPointToRay (Input.GetTouch(i).position);          
      
         if (Physics.Raycast (ray, hit, 1000))
         {  
          
             if(hit.collider.gameObject.tag == "handle") 
             {               
                 if (Input.GetTouch(i).phase == TouchPhase.Began) 
                 {           
                     scrollDistanceY = hit.collider.gameObject.transform.localPosition.y;
                 }
                 
                 if (Input.GetTouch(i).phase == TouchPhase.Moved) 
                 {  
                     var scrollDeltaY = Input.GetTouch(i).deltaPosition.y;
                     scrollDistanceY = Mathf.Clamp(scrollDistanceY+scrollDeltaY*Time.deltaTime*.8,-verticalLimit,verticalLimit);
                 hit.collider.gameObject.transform.localPosition.y = scrollDistanceY;  
                 }
 
              }
             }
   }
  }
 
              Answer by whydoidoit · Jun 13, 2012 at 09:29 AM
Just make scrollDistanceY an array of 10 long and then use "i" as an index into it too.
Your answer
 
             Follow this Question
Related Questions
I try to Create a DLL for get WM_TOUCH windows message! 1 Answer
Ragdoll 2D character controller help 0 Answers
Asynchronous Multi-Touch help - keeping track of touches and corresponding gameObjects (Android) 1 Answer
How can I make a gameobject to scale in a single direction? 2 Answers
How to force Eventsystem Drag 1 Answer