Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by pretender · Jun 21, 2010 at 10:07 AM · screenzoombounds

using objects bounds to zoom in object

hi everybody! i am trying to figure out how to calculate the zoom of the object based on its bounds so it fills out the screen completly.i have a lot of objects in the scene and all of them are different sizes, when i click on some of them, the zoom in, the smaller ones dont get zoomed in enough. i have a constant zoom factor which i would like to calculate based on objects bounds. how should i do this? does screen width and height plays any role here?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image drudiverse · Jul 07, 2014 at 11:00 AM 0
Share

Just glanced at this thread, i have somethine that is abit inversly true:

its a code that makes the object the same size regardless ofthe distance of teh camera by changing the object size as it moves away, it looks always the same...

ins$$anonymous$$d of obj size you can change the cam distance variable:

     var worldSize :float = (2 * $$anonymous$$athf.Tan(fov / 2.0)) * testdistance;
     var size :float = 0.25f * worldSize;
     var screen = 50.0/$$anonymous$$athf.$$anonymous$$ax(Screen.width,Screen.height);
     cube.transform.localScale = Vector3(screen*size, screen*size, 0.0001); //flat square seen from front, should 

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Tetrad · Jun 21, 2010 at 03:26 PM

Screen width/height shouldn't play a role. What should play a role is the camera's FOV (and possibly near/far clip planes). The FOV in Unity is vertical.

I don't know the math offhand, but you could figure out for a given height how far away from the camera you need to be for it. According to this thread, it's simply using the tangent of the FOV.

Alternatively, you might be able to whip up a solution by calculating the camera frustum planes and moving forward until they are no longer in bounds

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image pretender · Jun 22, 2010 at 10:18 AM 0
Share

although i didnt use your solution i thank you..i managed to resolve the issue in an uncomplicated way and that was to look for object bounds, like this collider.bounds.size, that is the Vector3, then to look the highest value and to set the distance to that value. in that way i have smaller and bigger object to fill out the screen when zoomed in... thanks everybody!

avatar image drudiverse · Jul 07, 2014 at 11:02 AM 0
Share

There is a caveat on that... If you get the zoom ok for a PC with 1920 pixels, and you send your project to someone with a small screen or a smartphone, it could be unpredictable... but indeed it should be vaguely ok.

avatar image BudyDubby · Jun 09, 2015 at 08:25 AM 0
Share

@pretender , could you tell me how to look at the highest value of vector3 ? i've same problem.

avatar image
-2

Answer by AnaRhisT · Jun 21, 2010 at 10:46 AM

You can give them all tags, like size1, size2, size3, raycast and check the tags, if it's size1 so it'll zoom 2, size2 3.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

Implementing Camera bounds proportionally to its ortographic size 0 Answers

health bar that scale to the zoom 1 Answer

Is there an easy way to get on-screen render size (bounds)? 5 Answers

How to set screen boundaries? 1 Answer

Calculating 2D Camera Bounds With Zoom 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges