Android and iOS Multi-Touch

I apologize if this isn’t the best place to be posting this… I’m developing a game for Android and iOS devices that requires the player to tap individual objects on the screen as they appear. Missing the object results in losing the game.

Now, I have one feature I’d like to include where multiple objects appear at once, and the player must tap them both simultaneously. I’ve written some basic 2D Raycasting code to detect this, and it seems to work perfectly… sometimes…

It seems some times the multi-tap is registered and all goes well, other times it seems a third tap is registered halfway between the two touch points, and since this point does not collide with the two objects, this results in the player losing.

To be more specific, here is a generic version of the code I am using to detect multiple taps.

if (Input.touchCount == 2) {

    if (Input.GetTouch(0).phase != TouchPhase.Stationary ||
        Input.GetTouch(1).phase != TouchPhase.Stationary)
        return;

    Vector2 v1 = Camera.main.ScreenToWorldPoint(new Vector3(
        Input.GetTouch(0).position.x, Input.GetTouch(0).position.y));

    Vector2 v2 = Camera.main.ScreenToWorldPoint(new Vector3(
        Input.GetTouch(1).position.x, Input.GetTouch(1).position.y));

    RaycastHit2D h1 = Physics2D.Raycast(v1, Vector2.zero);
    RaycastHit2D h2 = Physics2D.Raycast(v2, Vector2.zero);

    if (h1.transform != null && h2.transform != null) {

        // TODO: do stuff

    }

}

Single taps are handled in the individual object’s OnMouseDown functions, while multiple taps are handled in a single Update method for all objects.

Looking back, I think I can fix the issue of the player losing when this third tap is registered by ensuring there is only one touch point in the OnMouseDown function, or moving the code to this Update function and doing it all with Raycasting. But I guess my real question is, how reliable is this? Is there a way to ensure the game is only available for download from Android and iOS devices that support two distinct touch points? I remember reading somewhere that the hardware design of certain mobile touchscreens don’t account for multiple touches if they are on the same row or column, and I obviously need this to work 100% of the time.

Could you point me to some resources on this? Or am I better off leaving out this feature? Thanks!

EDIT: The game has been testing on a Samsung Galaxy S3 API level 19 and an iPad Mini iOS 9.2. They have identical results.

What evidence leads you to the “third tap” conclusion here? If the code snippet posted is all that controls this system, how could a “third tap” do anything at all, given that it won’t run if the number of taps is anything except exactly two?

Might be able to get some better information with some Debug.Logs like:

if (Input.touchCount > 0) {
string output = "Touches ("+Input.touchCount+"): ";
foreach (Touch t in Input.touches) {
output += t.phase.ToString() + " "+ t.position.ToString()+"  .....  ";
}
Debug.Log(output);
}

The output lines will appear in your phone’s console, and this could give you somewhat better information regarding what’s really going on.

Sorry that probably wasn’t the best way to explain it. What I mean is that instead of registering the two taps, only one is registered. And the location of the one registered is directly between where the two physical taps actually are.

As I stated above, single taps are handled elsewhere. The fact that the the single-tap code is being called and not the double-tap code I posted above already proves that only one is being registered.