# How to calculate the distance from the camera to make a GameObject fill the screen?

How do you calculate the distance from the camera so that a GameObject fills the screen? I.e. Without reaching out of the view and regardless of screen orientation.

## 1 Answer

You can return the difference of transform.position of Main Camera and transform.position of GameObject, if you only want the distance between them.

If you want something else, I think this video might help you

https://www.youtube.com/watch?v=MFQhpwc6cKE

• I think OP is asking not for the current distance between the object & camera, but the required distance they'll need to move the camera to in order for the whole object to fit on screen. May 11 '19 at 21:34
• Sarvagna Shukla, thanks for your contribution. @DMGregory you're right, it's about finding the required distance to make a GameObject fit onto on the screen. I've edited the question to make it more clear. Thanks for your feedback. May 11 '19 at 22:30