2 players camera setting

I’m producing a game from a top-down view perspective.
Two player characters play a cooperative game.
The camera moves with a target of the midpoint of two players.

The code was written to prevent the player from leaving the screen due to the calibration value.

rigid.MovePosition( SetKeepInScreen(movePosition) );
Vector3 SetKeepInScreen(Vector3 movePos)
{
    Vector3 pos = cam.WorldToViewportPoint(movePos);
    if (pos.x <= 0.11f) { pos.x = 0.11f; }
    if (pos.x >= 0.89f) { pos.x = 0.89f; }
    if (pos.y <= 0.06f) { pos.y = 0.06f; }
    if (pos.y >= 0.79f) { pos.y = 0.79f; }
    return cam.ViewportToWorldPoint(pos);
}

But let’s say only one player has moved to the limit of the screen,
The remaining players will span the limit on the other side of the screen. As a result, if the player who was stopped moves and enters the screen due to the calibration value, there is room for the screen limit of the player who was moving and moves more, As a result, if two players move, the camera will continue to move in one direction. Tell me how to limit the camera to be smart I beg you.