I use following code for measure touch delata position:
private Touch firstDetectedTouch;
public Vector3 dragDistance;
void Update() {
if (Input.touchCount > 0) {
firstDetectedTouch = Input.GetTouch(0);
if (Input.GetTouch(0).phase == TouchPhase.Moved) {
dragDistance = firstDetectedTouch.deltaPosition;
}
}
}
Then I sent dragDistance to my Player script and use it to move character as follow:
body2D.AddForce(speed * touchPhase.dragDistance * Time.deltaTime, ForceMode2D.Impulse);
On some devices(e.g Samsung Galaxy s3) it works as I expect. I can smooth control my character. But lately I had oportunity to test it on another device like Sony Xperia M2 and the result is terrible. To be honest it’s unplayable. Sometimes character moves very slow other times it’s rush as crazy. I don’t know it’s because I use this function wrong or missunderstand concept of delataPosition?