- Home /
2D bounding box in screen space from a 3D object
I'm trying to calculate a tight 2d bounding box around around a 3D gameobject in screen space. Basically so I can take a screenshot with the tightest possible rectangle drawn around my object. I can create a 3D bounding box that hugs my gameobject, and then I transform those coordinates into screen space with something like this:
Vector2 screenPoint = Camera.main.WorldToScreenPoint(world);
screenPoint.y = (float)Screen.height - screenPoint.y;
And then I just collect the max and min x and y values. I have written two approaches on my own and tried out everything I saw in this answer: https://answers.unity.com/questions/49943/is-there-an-easy-way-to-get-on-screen-render-size.html
But always the box is a bit larger than my model and I don't know why. The answer above hints at it having something to do with perspective, camera angle and axis alignment but not what to do about it. Does anyone have any idea on how to make this boundary tighter? Or even just why it ends up with a margin around it all the time?
Your answer
![](https://koobas.hobune.stream/wayback/20220613021532im_/https://answers.unity.com/themes/thub/images/avi.jpg)