How to smoothly move camera in 2D game?

my 2D game has a large map. I want the player to scroll the map using his finger.
Player can also zoom the map.

The scrolling is working but the camera movement does not match the movement of the finger. Either camera is moving too fast or too slow.

Without “authoFactor” movement is really fast (almost unplayable). With the factor it becomes a manageable under any zoom condition. But it does not match the finger movement, too slow.

Can anyone suggest how to improve this code?

if (isMousePressed && Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Moved)
    currentOthoSize   = Camera.main.orthographicSize;

    float authoFactor = currentOthoSize / originalOthoSize;

    Touch touch       = Input.GetTouch(0);
    Vector3 diff      = -touch.deltaPosition * Time.deltaTime * authoFactor;



private void AdjustCameraPositionForTranslate(Vector2 midPoint)

    float possibleWidth      = currentOthoSize * Camera.main.aspect;

    float possibleTop        = originalOthoSize - currentOthoSize;
    float possibleBottom     = currentOthoSize - originalOthoSize;
    float possibleLeft       = originalLeft + possibleWidth;
    float possibleRight      = originalRight - possibleWidth;

    cameraTransform.position = new Vector3(Mathf.Clamp(cameraTransform.position.x + midPoint.x, possibleLeft, possibleRight), Mathf.Clamp(cameraTransform.position.y+ midPoint.y, possibleBottom, possibleTop), cameraTransform.position.z);


Try this:

Vector3 diff = -touch.deltaPosition * (X + distance) / X * Time.deltaTime

“X” is a virtual distance from “player`s eye” to screen, it depends on FOV of your camera , and maybe smth else… but you can just pick it empirically and leave it constant :slight_smile:

Not tested, but this is a way I would try first :slight_smile: