- Home /
¿Unity messing up fingerIDs? [Android]
Mar'ri mar'ri, I hope you are fine today.
I am having a problem using multitouch and fast gestures, or rather, discrete touches mistaken as fast moves.
¿ Should I find or make my own touch detection ?¿ Is this a known issue with a simple solution ?
Precise : When making two consecutive taps, very "close in time", Unity tells me it's the same fingerID moving super fast, while the android system notices the difference between touches.
(To test this I activated the "show touches" option of the Android system and made a simple Unity app to draw it's opinion, and it draw a line between the taps, because it thinks it's the same fingerId, but the Android debug does not draw such connection)
"very close in time" - like within 1/50sec (or whatever your frame rate is)?
It seems perfectly possible that Unity is polling your touch input at a lower rate than the Android debug utility (which I assume runs at the native OS level), so a finger that is removed and replaced within a single frame's processing would not be noticed by Unity. I don't know this though - just a hypothesis.
I hope it's not the case, because then I will be forced to make my own input?? I will make further tests as Bunny says... There still is the chance I made the readings wrong
Answer by Bunny83 · Jan 07, 2016 at 04:56 AM
Uhm, are you sure you don't get a TouchPhase.Ended / Canceled and for the second touch a TouchPhase.Began? If the first touch has ended then of course the second touch would get the same fingerID. The FingerID is only valid between "Began" and "Ended / Canceled". The moment you lift the finger from the surface there's no way to keep tracking the finger. At that point the fingerID has lost it's meaning. If a new touch occures (TouchPhase.Began) that finger will get a currently free fingerID. In most cases it's picks the lowest free ID.
Example:
finger event ID
--------------------
F1 down 0
F2 down 1
F3 down 2
F3 up - // id 2 is now free
F1 up - // id 0 is now free
F3 down 0
F1 down 2
As you can see once we lift finger 1 and 3 those ids are free again. Because finger 3 touched again it gets lowest free id which is 0. If the finger isn't touching the surface it doesn't exist from the point of view of the touch hardware. When finger 3 touches again it's just a "new finger".
Can you post the example code you used to test this? Do you actually check the touch phase?
Keep in mind that with 3 fingers on the screen it's possible that the hardware looses track of one because depending on the positions it's possible that two fingers are "shadowing" the third. It's a similar problem like key ghosting in keyboards. As long as the fingers don't share the same column and row at the same time it shouldn't happen.
problem no problem
------(2)
(1)------(2) (1)------
| |
| |
| |
(3) (3)
"1" might be invisible to the hardware. I've also seen hardware that has already problems with only two fingers when they are on the same row.
I'm pretty sure I check that out, but I will make a more precise test just to be sure... I hope to be wrong, since that should fix it, thanks anyway. I'll check it and tell you
ah, you are Bunny! Dude you dont know the times I used your answers... you are like an Answer God... you gave me tons of helps with the Unity's GUI system without noticing, ja
The problem was exactly what you said (first)... I was messing up...
To confirm this I used a $$anonymous$$onoBehaviour attached to the Camera testing touches... but as a side effect I noticed that Unity seems to show the last recorded state of a finger... meaning.. a finger that makes 3 moves in one frame will only show the last one... and this is important if you are counting on Touch.deltaPosition. You can check this out using this script with the Android debugging feature "show finger position"
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class TestDedosGenerico : $$anonymous$$onoBehaviour
{
public $$anonymous$$aterial mat;
public float radioLinea = 3;
public float[] radiosFiguras = new float[]
{
12,11,10,9,8
};
public Color colorLinea = Color.white;
public Color[] colores = new Color[]
{
Color.green,Color.cyan,Color.gray,Color.red,Color.magenta
};
List<Touch> touches = new List<Touch>();
List<Vector3> pantalla = new List<Vector3>();
#if UNITY_EDITOR
void Reset()
{
if (mat == null) mat = new $$anonymous$$aterial(Shader.Find("Sprites/Default"));
}
#endif
void Update()
{
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Escape)) touches.Clear();
touches.AddRange(Input.touches);
}
void OnPostRender()
{
GL.Push$$anonymous$$atrix();
GL.LoadPixel$$anonymous$$atrix();
mat.SetPass(0);
foreach (Touch t in touches)
{
Linea(t.position, t.position - t.deltaPosition, radioLinea, colorLinea);
Rombo(t.position, radiosFiguras[(int)t.phase], colores[(int)t.phase]);
}
GL.Pop$$anonymous$$atrix();
}
void Rombo(Vector3 a, float radio, Color c)
{
GL.Begin(GL.QUADS);
GL.Color(c);
GL.Vertex(a + Vector3.up*radio);
GL.Vertex(a + Vector3.left * radio);
GL.Vertex(a + Vector3.down * radio);
GL.Vertex(a + Vector3.right * radio);
GL.End();
}
void Linea(Vector3 a, Vector3 b, float radio, Color c)
{
Vector3 volumen = (b - a).normalized;
volumen = new Vector3(-volumen.y, volumen.x, 0) * radio;
GL.Begin(GL.QUADS);
GL.Color(c);
GL.Vertex(a - volumen);
GL.Vertex(a + volumen);
GL.Vertex(b + volumen);
GL.Vertex(b - volumen);
GL.End();
}
}
Your answer
Follow this Question
Related Questions
multiTouch problem when fingers close together (Bug?) 1 Answer
multi-touch woe, index out of bounds? 1 Answer
Touch Input madness 2 Answers
Android - touch a 3d object and something happens to it 1 Answer
input touch android help 0 Answers