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
0
Question by Rookas · May 12, 2015 at 10:49 AM · camera movementcamera viewportorthographic camera

How to make the camera show only the part of the world which is in a specified rectangle?

Hello,

In my game, I have code which determines a bounding box that encloses all the players in the game:

alt text

The bounding box is defined by four float numbers, xmin, xmax, ymin, ymax (which is effectively a Rect).

I want the camera (I'm using orthographic) to show only as much of the game world as the bounding box encloses. Every frame, as player positions change, the bounding box is recalculated accordingly, and so should the camera. I expect smooth changes in the camera since the box is also updated gradually, once per frame.

I tried to accomplish the desired camera motion by changing the camera's orthographicSize or its position as follows:

 Camera.main.transform.position = new Vector3(m_Viewport.center.x, m_Viewport.center.y, -1);
 Camera.main.orthographicSize = 0.5f * m_Viewport.height;

m_Viewport is a Rect that is my bounding box.

The first line matches the center of the bounding box with the camera position. The second line is based on the fact that the orthographic size is half the height in game units.

While the position seems to work OK, the zooming behaviour (`orthographicSize`) is off. Only by moving the camera to the center of the bounding box I can't achieve the behaviour that only the inside of the box be seen; things outside are also captured by the camera. I believe the orthographicSize is the culprit but how do I choose the right value for it?

Thanks, Rokas

untitled.png (20.1 kB)
Comment
Add comment · Show 2
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 FortisVenaliter · May 12, 2015 at 09:37 PM 0
Share

I'm not 100% on one thing... do you want it to appear bordered like the image where everything outside the rect is empty space, or do you want to zoom the camera to make the screen represent the rect?

avatar image Rookas · May 13, 2015 at 07:18 AM 0
Share

I want to zoom the camera to make the screen represent the rect.

0 Replies

· Add your reply
  • Sort: 

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

2 People are following this question.

avatar image avatar image

Related Questions

How to properly set camera sizes in 2D Ortho camera split screen? 0 Answers

Camera zoom AND smooth transition? 0 Answers

Camera preview only shows skybox 7 Answers

How to make a split screen, one for a main camera and one for the VR set camera? 1 Answer

My Scene View is Fine but my Game View is just black but the Camera Works 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