Hello, I’m pretty new to Unreal. I was trying to implement a ZoomOut feature for a “”“racing game”"" so I need my camera to always include all the players (4) into his view. I’ve succesfully managed to point it to the centroid built from the players’ positions but sometimes not all players fit into the view. How can I check if a player is out of the camera view? And consequently adapt the camera height or rotation in order to include all the players into the view?
You can use a “Was Recently Rendered” node to see if an actor is in camera view (note that if you see the car shadow but not the car itself, Was Recently Rendered will also return True; I think the same applies to effects like particles etc.)
But I believe that with the correct math you won’t have to do that.
On option as I see it is this:
- get location of all 4 cars, determine the max and min X and Y coordinates (add/subtract some values to encompass the entire car, not just its center point).
- set the camera’s X and Y to (Xmax+Xmin)/2 and (Ymax+Ymin)/2 respectively.
- subtract Xmax - Xmin, Ymax - Ymin, see which result is higher (Xdelta or Ydelta).
- next, the easiest way to do it is if your camera’s Field of View is 90 degrees. Let’s say Xdelta is higher; just divide it by 2 and set the camera’s Z to (Xdelta/2) + Ground Z coordinate + maybe some additional value for the cars not to be at the very edge of the screen
- But if the Field of View is not 90 degrees, you’ll have to do some math (trigonometry) to see how high should the camera be.
Hope this helps.
But this would make the camera x and y change right? I just wanted to modify its z and rotation. I could check every tick if every player is being rendered and make z higher accordingly but zooming in would be a problem this way.