Camera Touch pan movement inconsistent across different screen resolutions.

I currently have this code.

``````if (Input.touchCount == 1) {
if (Input.GetTouch (0).phase.Equals (TouchPhase.Moved)) {
NewPos += new Vector3 (
-Input.GetTouch(0).deltaPosition.x/Screen.width*panSpeed,
0,
-Input.GetTouch(0).deltaPosition.y/Screen.height*panSpeed
);
}
}
``````

which is my attempt to normalize the Touch deltaPositions. but even after dividing with screen width/height, I still notice a massive difference in speed when running it on my phone, compared to the smaller window in unity.

My phone has a resolution of 1280x720. and android phones range from everything between 480p to 2k screen resolutions.

Is there a way to make the camera movement speed consistent across all devices?

This post is from 2014 but i think many people might have the same question. This is my solution:

``````    public float minXPos = -12f;
public float maxXPos = 100f;
public float minYPos = -100f;
public float maxYPos = 100f;
void Update()
{
if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Moved)
{
float screenSize = Mathf.Max(Screen.width, Screen.height);
Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
Vector2 touchDeltaPercentage = touchDeltaPosition / screenSize;

Vector3 screenCenter = new Vector3(Screen.width * 0.5f, Screen.height * 0.5f, 1f);
Vector3 screenTouch = screenCenter + new Vector3(touchDeltaPosition.x, touchDeltaPosition.y, 0f);

Vector3 worldCenterPosition = Camera.main.ScreenToWorldPoint(screenCenter);
Vector3 worldTouchPosition = Camera.main.ScreenToWorldPoint(screenTouch);

Vector3 worldDeltaPosition = worldTouchPosition - worldCenterPosition;

//touchDeltaPercentage values will now range from 0 to 1

//define camera border in minXPos, maxXPos, minYPos and maxYPos
transform.Translate(-worldDeltaPosition);
Vector3 tmpPosX = transform.position;
tmpPosX.x = Mathf.Clamp(tmpPosX.x, minXPos, maxXPos);
transform.position = tmpPosX;

Vector3 tmpPosY = transform.position;
tmpPosY.y = Mathf.Clamp(tmpPosY.y, minYPos, maxYPos);
transform.position = tmpPosY;
}
}
``````