Multiplayer Shared Camera Similar to Smash Bros.

I’m working on a 2.5D game and want to make a shared camera which zooms in or out to fit all the players on screen. Currently in Tick(), I’m taking a list of all active players and finding the min and max Y and Z locations in the form of a bottom left vector and a top right vector which form a rectangle. Right now I’m positioning my camera on the average of the two vectors so it’s in the center of the bounding rectangle.

What I can’t figure out is a good way to calculate the camera’s position along the depth axis (X in this case) so that it is zoomed in/out enough to capture all the players (the entire bounding rectangle). Does anyone know of a good method for controlling this type of shared camera?

Here is what the Tick() looks like so far:

void ATopSpinCamera::Tick(float deltaseconds)
{
	PlayersInScene = Cast<AMaximumTopSpinGameMode>(GetWorld()->GetAuthGameMode())->GetActivePlayers();
	FVector BottomLeft;		//needs initializing to a min value
	FVector TopRight;		//needs initializing to a max value
	for (AMaximumTopSpinBall* ball : PlayersInScene)
	{
		FVector ballLocation = ball->GetActorLocation();
		if (ballLocation.Y < BottomLeft.Y)
			BottomLeft.Y = ballLocation.Y;
		else if (ballLocation.Y > TopRight.Y)
			TopRight.Y = ballLocation.Y;
		if (ballLocation.Z < BottomLeft.Z)
			BottomLeft.Z = ballLocation.Z;
		else if (ballLocation.Z > TopRight.Z)
			TopRight.Z = ballLocation.Z;
	}
	//set destination to (BottomLeft + TopRight)/2
	//set X value of destination???
	//lerp to position
}

Well, I’ve come up with a temporary solution with a bit of reasoning behind it.

Since the default camera’s horizontal FOV is 90 degrees, the angle from directly where it is looking to the edge of its view is 45 degrees. And since it’s staring directly head on at a 2D plane, the view vector forms a right angle with the playing plane. In other words…

As seen with that triangle, the distance the camera is panned out, edge BC, should be equal to half the rectangle’s horizontal (or half the rectangle’s vertical, if that’s greater), which is edge CA. That amount plus a small flat offset seems to give good results.