Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 qua1ity · Oct 06, 2019 at 01:01 AM · resolutioncamera viewportaspect ratio

Cinemachine confiner on different aspect ratios

I have a basic Cinemachine camera setup which follows the player and I added a confiner to limit the camera's position. The bounding area for the confiner is just polygon collider formed as a square on the background.

I only support landscape mode and started off with a 16:9 aspect ratio, where everything is fine. My problem is when the aspect ratio changes to for example 2:1. Then the camera becomes a bit wider than my defined bounding/confined area and the confiner pretty much breaks.

This is how it is supposed to work: https://imgur.com/a/I5DAHtn
And this is the result of a wider resolution: https://imgur.com/a/tzIAahx
(The yellow border is the collider being used as a confiner and the white is the camera).

How do I get around this problem? Can you dynamically change the confiner to never be smaller then the camera view? Or do I have to adjust the camera size somehow? Currently using an orthographic camera with a size of 5.

Not sure what to do here, any help is appreciated!

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by kunf · Apr 16, 2020 at 06:14 PM

One of solutions - add script to colliders used as confiner boundaries. In my case - my colliders are rectangle and initially used for 16:9 aspect. For 16:10 i need to make colliders 3.2 units wider, if they have width. And keep zero width for any colliders with zero width no matter which aspect ratio is used.

     void Awake()
     {
         if(Camera.main.aspect == 16.0f/10.0f)
         {
             var allPoints = GetComponent<PolygonCollider2D>().points;
             for (int i = 0; i < allPoints.Length; i++)
             {
                 if (allPoints[i].x < 0)
                 {
                     allPoints[i].x -= 1.6f;
                 } else
                 {
                     if (allPoints[i].x > 0)
                         allPoints[i].x += 1.6f;
                 }
             }
             GetComponent<PolygonCollider2D>().points = allPoints;
         }
     }
Comment
Add comment · Show 1 · 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 kunf · Apr 16, 2020 at 07:00 PM 0
Share

And more flexible version for supporting any aspect ratio:

     float orthoCameraSize = 9.0f;
     void Awake()
     {
         float aspectFix = Camera.main.aspect * orthoCameraSize;
         Vector2[] allPoints = GetComponent<PolygonCollider2D>().points;
         for (int i = 0; i < allPoints.Length; i++)
         {
             allPoints[i].y = ($$anonymous$$ath.Abs(allPoints[i].y) - orthoCameraSize) * $$anonymous$$ath.Sign(allPoints[i].y);
             allPoints[i].x = ($$anonymous$$ath.Abs(allPoints[i].x) - aspectFix) * $$anonymous$$ath.Sign(allPoints[i].x);
         }
         GetComponent<PolygonCollider2D>().points = allPoints;
     }

I made my colliders exact size of room. And write orthographic camera size in script ins$$anonymous$$d of reading from camera, because using perspective camera. Script shrinking my rectangle colliders depending on aspect, so camera will always show only contents bounded by collider.

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

113 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Outside game clear screen 0 Answers

Unity 2D Scaling For All Mobile Devices. What Resolution to use to keep Sprites Sharp and Avoid Blurriness? 1 Answer

Problems with camera and screen resolutions 1 Answer

Is there a way to keep camera and UI always the same? 1 Answer

Stretch Colliders when changing resolutions ? 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