Strange touch data during multitouch

I’m testing out an Android implementation of some stuff that works perfectly on the iPhone and I’m getting some weird results when using multitouch. If I touch with one finger, I get proper consistent results. When I go with the second finger, I get very strange mixed results in the touches data. As I loop through each touch in the touches data, the resulting x and y data is often times mixed up. As in, for finger 1, I’m getting x coordinates for finger 1 and y coordinates for finger 2, while for finger 2 I’ll get the opposite.

Is it possible there is a bug in the Android touch data or am I somehow doing something wrong? I’m curious to know if anybody has seen this either work properly or has seen similar results to what I’m seeing.

I’m running on the Google Nexus One that we got with our Unity Android License. All touch update code is performed in the Update function, where I’m storing it off and using it later in my OnGui function.

BAH. I just downloaded this app:

And I’m seeing the same results. Is there something wrong with my Nexus One, or is it normal for Android multitouch data to be garbled like this?

BAH AGAIN. Sorry to “solve” my own problems, but I just found this article:

Which shows exactly what I’m seeing in that test app and in our Unity app. Bummer.

This thread can now be used to complain about your Nexus One and/or multitouch in Android.

I also have a Nexus One and I’m getting strange results with Multi touches which do not happen on iOS.

I have a ship that moves from left to right by placing one finger on the touch screen and sliding from side to side. The second finger is used for tapping as a fire button anywhere on the screen. This is set up as a top view shooter.

On iOS the ship moves very smoothly while gliding the first finger side to side. If I stop moving the 1st finger but leave it placed on the screen the ship stops moving. You need the first finger placed on the screen before you can tap the fire event with the 2nd finger.

After getting Android 2.2.1 OTA the ship jumps around and fidgets / shakes constantly. If I stop moving the first finger but leave it placed on the screen it continues to shake. Note I patched the player shake below. However, strange behavior will occur if you happen to tap the screen anywhere above or below the first fingers position. I guess they call this crossing the axis between two fingers. The problem will persist even if there is a large gap between fingers.

Can someone from Unity Support comment here or PM me directly thanks.

// In Player C# script
public float speed  = 10f; 
public float margin = 1f;
void Start () {
      cameraLimit = Camera.mainCamera.orthographicSize;
}
 
void Update () {
float amtToMove; 
 
foreach (Touch touch in Input.touches)
{
if (touch.phase != TouchPhase.Ended  touch.phase != TouchPhase.Canceled)
 {
 if (touch.fingerId == 0)
  {     // added patch to remove stationary screen shake
    amtToMove += (int)touch.deltaPosition.x * (speed*.01f);
  }
elseif (touch.fingerId == 1  touch.phase == TouchPhase.Began)
  {
    Instantiate(bulletPrefab, bulletPos, Quaternion.identity);
  }
 }
}
// move with borders
if ((transform.position.x - margins + amtToMove) < cameraLimit 
                   (transform.position.x + margins + amtToMove) >-cameraLimit)
                transform.Translate(Vector3.right * amtToMove);
}

TEST 2 of Multi Touch Bug

Simply drag and drop Player.cs script on an empty GameObject and then build program for both iOS and Android.

You will notice that iOS is smooth. If you hold two fingers still you will get ‘Stationary’ and 0,0 for x y movements.

On Android you will not see a steady ‘Stationary’ status ever. Also the x y values jump around as floating points #'s. Also if you use a ‘pinch’ gesture finger one swaps places with finger two!

using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour {
    string fid1;
    string fid2;
	
	void Update () {
        fid1 = "OFF";
        fid2 = "OFF";
	// Hold two fingers still
        foreach (Touch touch in Input.touches)
        {//in iOS you see int's and stationary, in Android you see floats  always moved...
        if (touch.fingerId == 0 )
           fid1 = touch.phase.ToString()+
					"\n    x,y: "+touch.position.x+", "+touch.position.y+
					"\nDx,Dy: "+touch.deltaPosition.x+", "+touch.deltaPosition.y;
        else if (touch.fingerId == 1 ) 
           fid2 = touch.phase.ToString()+
					"\n    x,y: "+touch.position.x+", "+touch.position.y+
					"\nDx,Dy: "+touch.deltaPosition.x+", "+touch.deltaPosition.y;  
        }
    }

    void OnGUI()
    {
        GUI.Label(new Rect(100, 50, 200, 100), "TOUCH PHASE STATUS: ");
        GUI.Label(new Rect(100, 100, 300, 200), "FINGER1: " + fid1);
        GUI.Label(new Rect(100, 300, 300, 400), "FINGER2: " + fid2);
    }
}

This is a well known bug, that only happens on HTC devices like the Nexus One and the HTC Desire.
It is a hardware restriction, that cannot be solved through software.
You can circumvent it, if you don’t let the axes cross or even better, support the additional trackball/digipad you get when you come over from Iphone.

Unfortunately, it’s not well known enough for those of us making our first splash in to Android development. I spent a day fighting with this, trying to figure out why our stuff wasn’t working right.

I’d highly recommend that the folks at Unity put some kind of warning in the Unity Android documentation, especially since the phone they are giving away suffers from this fatal flaw.

You’re right, BuzzJive, android docs need some love. We’re working on them at the moment.

Hi!

I tried porting our games to Android too, and got the multi-touch issues on the Nexus One.

However, I’ve played Assassin’s Creed on the same device, and the multi-touch works just fine there.

Could you please check if there are any workarounds you could do in Unity, to make the games work on the Nexus One (and other devices with similar issues)?

Thank you,
Bogdan

According to Wikipedia: “ClearPad 2000 sensor supports multi-touch gestures limited to single finger input and 2x1D two finger gestures”.
So, the question is then; what type of multi-touch is “working fine” and what type of multi-touch are you trying to support / what issues do you see?

You move the two analog controls so that they are slightly above each other. Never have to two fingers directly parallel to each other.

Seeing this on the Droid 2 as well. Nothing much in the docs yet.

Seems like the touches don’t have to be directly parallel for this to happen, either. Is there a set pixel range that causes this?

Did you download the android app I linked to above? It’s a simple visual tool to visualize the problem. I’m disappointed to hear the droid 2 has this problem. I’ve only tested on 2 devices - the Nexus One, which has this flaw, and a newer myTouch (not sure the exact model), which worked just fine. It would be nice to have a full list of devices that had this flaw.