I have a problem with correct touch position detection. When I try to detect single touch the system detect touch position correctly, also in two touches case. But when I try to detect two touhes and the distance between them became pretty less the positions start “swapping”. So I think this is strange behavior of input system. Maybe someone faced with this promblem?
matureopulentamericanwigeon
using UnityEngine;
using UnityEngine.UI;
public class TouchDetector : MonoBehaviour
{
public Text DebugText;
public Transform[] TouchMarkers;
private void Update()
{
DebugText.text = "";
for(int i = 0; i < Input.touchCount; i++)
{
Touch touch = Input.GetTouch(i);
DebugText.text += string.Format("FingerID: {0} SreenPostion: {1}\n", touch.fingerId, touch.position);
TouchMarkers[i].position = (Vector2)Camera.main.ScreenToWorldPoint(touch.position);
}
}
}
I doubt this is a Unity-related problem. If you move two fingers too close together, the touches may be recognized as a single touch. The touch screen manufacturer uses some algorithms to determine what is a touch and what is not, based on the capacitance and the area. These algorithms need to work with large fingers, but also the fingers of children. So bringing two fingers very close together can cause the touches to be detected as one… and since you are no machine, tiny movements can result in the touches being recognized as two again. When the detection goes from one to two touches, it’s not guaranteed (not sure if it’s actually undefined tho) that the same finger remains ‘touch 0’.
After all, how would the system know which of the fingers was touch 0 before?
You would have to come up with your own hueristics to try and fix this. For example look for a big jump in touch positions between frames or a switch from two touches to one and try to use previous known touch positions from previous frames to make a better guess about which finger is actually where. It’s unfortunately the kind of problem that humans are more suited to than computers.