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 Kujo87 · Oct 14, 2013 at 10:22 AM · camerarect

Move the viewport, but maintain its size.

Is there a way to use the Normalized View Port Rect but maintain its size? When I adjust the x and y at the, the viewport shrinks. I need to be able to keep it at Screen.width and Screen.height, but move it.

Is this possible?

Thanks

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

2 Replies

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

Answer by Kujo87 · Nov 07, 2013 at 03:36 PM

Sorted this now. For anyone wanting to do similar in the future, I did it using this:

CamScript.cs:

  void OnPreCull()
         {
             var r = new Rect(0f, 0f, 1f, 1f);
             var alignFactor = Vector2.one;
             if (viewportOffset.y >= 0f)
             {
                 // Sliding down
                 r.height = 1f - viewportOffset.y;
                 alignFactor.y = 1f;
             }
             else
             {
                 // Sliding up
                 r.y = -viewportOffset.y;
                 r.height = 1f + viewportOffset.y;
                 alignFactor.y = -1f;
             }
     
             if (viewportOffset.x >= 0f)
             {
                 // Sliding right
                 r.width = 1f - viewportOffset.x;
                 alignFactor.x = 1f;
             }
             else
             {
                 // Sliding left
                 r.x = -viewportOffset.x;
                 r.width = 1f + viewportOffset.x;
                 alignFactor.x = -1f;
             }
     
             // Avoid division by zero
             if (r.width == 0f)
             {
                 r.width = 0.001f;
             }
             if (r.height == 0f)
             {
                 r.height = 0.001f;
             }
             camera.rect = new Rect(0, 0, 1, 1);
             camera.ResetProjectionMatrix();
             Matrix4x4 m = camera.projectionMatrix;
             camera.rect = r;
     
             Matrix4x4 m2 = Matrix4x4.TRS(
              new Vector3(alignFactor.x * (-1 / r.width + 1), alignFactor.y * (-1 / r.height + 1), 0),
              Quaternion.identity,
              new Vector3(1 / r.width, 1 / r.height, 1));
     
             camera.projectionMatrix = m2 * m;
         }

Usage:

 Vector2 screenPos = gameCamera.WorldToScreenPoint (new Vector3 (transform.position.x, transform.position.y, _dartDistance));
 screenPos = gameCamera.ScreenToViewportPoint (screenPos);
 screenPos = new Vector2 (-Utils.NewRangeCalc (0.0f, 1.0f, -0.5f, 0.5f, screenPos.x), -Utils.NewRangeCalc (0.0f, 1.0f, -0.5f, 0.5f, screenPos.y));
     
  CamScript.viewportOffset = screenPos;

The OnPreCull method has its origin in the centre so I had to scale the screenPos from 0-1 to -0.5-0.5 to get it to work right.

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
avatar image
0

Answer by Cherno · Oct 14, 2013 at 01:22 PM

It's possible, there is a user script of a minimap camera where you can specify the dimensions as well as the position on screen. I can'T remember it's name, you just have to search a bit for it.

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 Kujo87 · Oct 14, 2013 at 01:40 PM 0
Share

Can this be done during update? I'm after moving the viewport around on user input.

I've had a look around at some of the $$anonymous$$imap scripts after your suggestion, but most of them are making the viewport smaller (for a picture in picture look)... I require my viewport to stay the same size at all times and be full screen.

Thanks

avatar image sdgd · Nov 07, 2013 at 03:38 PM 0
Share

wouldn't it be easyer and same effect just to transform.position of camera?

avatar image Kujo87 · Nov 07, 2013 at 03:43 PM 1
Share

No as this doesn't give the desired effect I was looking for. It would either cause the object I'm moving round to distort with the perspective of the camera, or if I set the transform of the camera equal to the object I'm moving, it would appear not to move (as I was culling everything except for the object)

Its quite a specific effect I was looking for and achieved with the methods below

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

16 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

Related Questions

Build for Windows : Camera rect always stretched 0 Answers

camera.pixelrect not behaving properly 3 Answers

drawings secondary cameras in specifics places 1 Answer

set Edge Collider 2D to the borders of the camera's viewport 0 Answers

Changing the Camera viewport rect results in resizing the objects rendered by the specific camera ? 1 Answer


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