I think I found an Android bug. Deltatouch seems to be off by about 3 times. This fix allows me to move a few GUI elements at the same pace as my finger. Without *3, my movement lags behind my finger. Here’s my fix:
The Touch.deltaPosition is the change in position over that time, not over the time of the last frame (the Unity docs are slightly unclear on this, since the events themselves arrived during the last frame). This is why the sum of all Touch.deltaPosition values will not equal the difference between Touch.position values.
You can account for this as follows:
t.deltaPosition * Time.deltaTime / t.deltaTime
So, the code for dragging a scrollview would be:
position = GUILayout.BeginScrollView(position);
...
GUILayout.EndScrollView();
if (Event.current.type == EventType.Repaint) {
var area = GUILayoutUtility.GetLastRect();
for (var i=0; i<Input.touchCount; ++i) {
var t = Input.GetTouch(i);
var pos = GUIUtility.ScreenToGUIPoint(t.position);
if (area.Contains(pos)) {
if (t.phase == TouchPhase.Moved) {
var delta = GUIUtility.ScreenToGUIPoint(
t.deltaPosition * (Time.deltaTime / t.deltaTime));
position += delta;
}
}
}
}
No need for magic “multiply by 3”, nor anything to do with DPI etc.
Delta Position of touches is reliant on the phone hardware, thus, it is not uniform across all Android devices.
Typically, a touch screen nowadays takes the capacitance information from a thin and nearly invisible strip of transistors overlaid across your screen in the conductive substrate. This is where the hardware varies, and varies quite vastly in the android atmosphere.
I’ve always had to have an adjustment multiplier variable to change sensitivity in Android, and I would suggest you give this capability to users if you don’t want them complaining about poor controls on Android. This is a widely seen complaint with Android gamers, and it would be wise to take the time and try to smooth it out for as many people as possible.
In my somewhat limited experience with Android development, comparing touch position between frames can produce more intuitive results than using deltaPosition directly.
The fact that they return different values at all seems perturbing, but I can’t really comment on the internals involved.