Android Multi-Touch Issue

So I’ve been working with Unity Android for the past few weeks and have been struggling with one problem over and over and over again. I’ve gone through the documentation and even browsed through the Penelope scripts but I can’t find a solution to this problem.

I’m working on the Acer Iconia A200 and testing with a basic unity script:

	for(MoveFinger = 0; MoveFinger < Input.touchCount; ++MoveFinger){			
		if (Input.GetTouch(MoveFinger).phase == TouchPhase.Began){ //USE WHEN PORTING TO ANDROID

           if (Physics.Raycast (moveray, FingerHit, 200, MoveLayer) && Spinning == false) {
           		if(FingerHit.collider.gameObject.tag == "ReturnNull"){
           		}
           		if(FingerHit.collider.gameObject.tag == "MoveLayer"){
            		StartClickTimer = true;
					Debug.DrawLine(moveray.origin, FingerHit.point);
            		MoveTarget.position = FingerHit.point;
            	}
     		}           
   	 	}
 }

So the issue is this: it works perfectly when one finger is on the screen. When two fingers are on the screen it can’t differentiate between the old finger and the new finger and so it averages the distance between the two. Additionally, it occasionally can’t tell when a finger has been lifted from the screen and will read one finger as two.

What is a good workaround to this?
The penelope script referenced a concept called “latching”. How can I implement this?

Thanks in advance.

EDITED TO ADD NEWER/LONGER VERSION OF THE CODE

function Update(){

var MoveLayer = 1 << 8;

//Knowing the LerpDistance ensures constant Lerp Speed
var moveray = Camera.main.ScreenPointToRay (Input.GetTouch(MoveFinger).position); 
var ClickRay = Camera.main.ScreenPointToRay (Input.GetTouch(MoveFinger).position); 
var FingerHit : RaycastHit;
var ClickHit : RaycastHit;
var LerpDistance = Vector3.Distance(PlayerShip.transform.position, MoveTarget.position);

if(IsRotating == false){
	RotateTarget.localEulerAngles = Vector3(0,0, PlayerShip.transform.position.x * 2);
}
IsRotating = false;
MoveTarget.position.x = Mathf.Clamp (MoveTarget.transform.position.x, -12, 12);
MoveTarget.position.y = Mathf.Clamp (MoveTarget.transform.position.y, -6, 6);

// After 10 seconds of damage has passed, start restoring the shield
DamageTimer += 1 * Time.deltaTime;
if (DamageTimer >= 10){
	RestoreShield();
}


///If we're single clicking move at normal speed to the position
if(DoubleClicked == false && Spinning == false){
PlayerShip.transform.position.x = Mathf.Lerp(PlayerShip.transform.position.x, MoveTarget.position.x, Time.deltaTime / LerpDistance * ShipSpeed);
PlayerShip.transform.position.y = Mathf.Lerp(PlayerShip.transform.position.y, MoveTarget.position.y, Time.deltaTime / LerpDistance * ShipSpeed);
		PlayerShip.transform.rotation = Quaternion.Lerp(PlayerShip.transform.rotation, RotateTarget.rotation, Time.deltaTime * ShipSpeed/2);
}




		
		for(MoveFinger = 0; MoveFinger < Input.touchCount; ++MoveFinger){			
			if (Input.GetTouch(MoveFinger).phase == TouchPhase.Began){ //USE WHEN PORTING TO ANDROID
			FirstFingerID = Input.GetTouch(MoveFinger);
			MoveFinger = FirstFingerID.fingerId;
			print(FirstFingerID.fingerId);
	           if (Physics.Raycast (moveray, FingerHit, 200, MoveLayer) && Spinning == false) {
	          
	           		if(FingerHit.collider.gameObject.tag == "ReturnNull"){
	           		}
	           		if(FingerHit.collider.gameObject.tag == "MoveLayer" && FirstFingerID.fingerId == 0){
	            		StartClickTimer = true;
						Debug.DrawLine(moveray.origin, FingerHit.point);
	            		MoveTarget.position = FingerHit.point;
	            	}
	            	if(FirstFingerID.fingerId == 1){
	            	print("I suck");
	            	}
         		}           
       	 	}
       	}

}

The script basically moves a target named “MoveTarget” to a place in the world, designated by the player’s finger touching the screen. Then the script Lerps the Ship model towards that target. Simple, but broken

Okay, so I’m using Unity remote now for my debugging. I’ve been tracking my finger id’s and they seem to be working properly. When I put one finger on the screen, the number is 0, a second finger is 1, 2, 3 and so on.

Now, how would I use fingerId to continuously track the same one finger? I’m just unsure how to implement the code still.

Ok so firstly you need to move the moveRay and ClickRay construction inside the for loop where MoveFinger is being updated.

I’m guessing it’s just taking the wrong finger position and you will need to create a new ray for each finger, inside that loop.