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
}