Auto-Zoom Camera to See All Players?

Hi Unreal Community!
A lot like this question, I have a project (though unlike that one it’s 3D) where I want the camera to automatically move (and “zoom” by moving back and forth) to keep all the players on screen (like in Brawlhalla or Smash Bros, but 3D).
I tried recalculating and setting a springarm length each frame (looping over the ActorsOfClass), but that doesn’t seem to work, at least the way I did it.
How might I achieve this?
Thank y’all so much!!

P.S. pls keep in mind my game is 3D, and I would like each player to have a separate camera (so I can give each of them a different perspective).

2 Likes

I think you’re on the right track with ‘all actors’ and spring arm length. But what is the spring arm connected to?

The camera needs to be pointing into the center of mass of the players ( average vector type computation ). But I guess the height and pan over the players can be controlled by the user.

2 Likes

This is nowhere near perfect, but it has the right elements

pawns

On begin play I get the actors and count them

On each tick, I count how many I can see

and then change the spring arm length depending on that

Ideally, you want to make a calculation depending on how many actors are near the screen edge.

4 Likes

Thank you so much!! That’s amazing!

1 Like

Nice! @ClockworkOcean clokworkoc Thank you. This is something I have planned for a combat system.

After reading this topic yesterday I started prototyping and got about halfway to what I wanted. Suddenly 7+ hours had past and it was 5am to end with something that is probably extreamly overcomplicated. :rofl:

If you guys would like to keep this topic alive or start a new one to share ideas, I’m all for it.

Some quick thoughts for perpetuity:

  • From the cameras perspective I get the furthest actors top, left, bottom and right. This means looping through all of them per side.
  • I get their center and calculate the distance from left-> right and top → down to build a bounding box from the cameras perspective.
  • Finnaly (and the part where I passed out) I calculate the distance the spring arm has to be from the center taking into account the fixed width and FoV. This only takes into consideration horizontal, need to integrate vertical somehow.

This is how it looks like… not perfect but it’ll get there:
CameraZoomOnPlayers


  • Converting world location to screen is another alternative I was considering to redice the math a bit.
  • I did not take into account depth, so actors can go behind the camera. Think a solution is to always keep the spring arm a minimum distance from the closest actor to the camera looking from center out and have its length adjust if necesary.
  • Getting the center of the group is easy but an actor that is furthest in both vertical and horizontal can heavily influence the location.
2 Likes

I think it’s an algorithm that is heavily dependent on exactly how much leeway the characters have, and how much control over the camera the player has, and so on.

To get the optimal solution, you really need to know the constraints you’re dealing with, if any :slight_smile:

1 Like