#How to position the camera to include certain points on screen.

1 messages · Page 1 of 1 (latest)

unborn island
#

I'm trying to make a camera system that dynamically adjusts it's position to keep all relevant GameObjects in frame. Does anyone know the math required to do something like that?
I hope it doesn't require matrix math 🤞

viscid ginkgo
#

Some more information would be good like, is it 2d or 3d, perspective or orthographic? But in the end, you would calculate the fartherst top right bottom and left objects, get the distance relative to your screen resolution and then move the camera back for that amount of distance combined. Rotation would look at the average least distance between all tracked objects.

unborn island
#

Ah mb,
It's 3d, perspective, the camera isn't pitching or yawing but it is rolling along its forward axis.

proud prism
#

Obligatory: use Cinemachine, it has the feature built in. No maths required

unborn island
#

Looking to learn it for myself, do you think the code for it is readable to study it?

viscid ginkgo
#

If you just want to learn it, I would just start coding and see, how far I get. When getting stuck , you could read the cinemachine code, if it is readable at all. But a little testing and trying out if you do not have any time pressure is always good.

atomic walrus
#

The math is pretty simple. You're basically just calculating a bounding box followed by a little trigonometry with your fov. But you have to decide if you want to dolly or zoom to fit.

But yeah Cinemachine target group does this automatically.

unborn island
#

Oh yeah I guess it is pretty simple