Centering camera between 4 players

I’m trying to make a camera that will always target the “center” between 4 playes and zoom out if the distance between them increases (and zoom in when decreases).

I managed easily to get the center of those players, but I’m having a lot of problems with zoom in/out functionality expecially because I have to consider that a player me be also on a different height relative to the others.

Any help or links to tutorial is well appreciated

Edit 1
I’m asking also for a suggestion about how to calculate the center, my current idea is:

  1. Find the point between point1 and
    point2 (let’s call it between1)
  2. Find the point between between1 and
    point3 (call it between2)
  3. Find the point between between2 and

The other idea I have is this:

  1. Find the point between point1 and
    point2 (between1)
  2. Find the point between point3 and
    point4 (between2)
  3. Find the point between between1 and

But with this, I’m having some hard times with 3 characters :\

I would start the camera at the center you found, then zoom back a certain increment (you’ll have to figure out what works for you)

Then check to see if the palyers are all visible, using Renderer.isVisible()

Then, if they are not visible, move back again and re-check.

You ought to be able to do this many times in a single Update, so you should only see the end result.

As a matter of fact, it would work better with a while() loop…


while ( All four players !(Renderer.isVisible)) {
    Zoom back;

Once you have the center, your zoom should be given by the player the farthest from it, and that distance. Then you just push or pull the camera along forward.