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 YoshieMaster · Oct 17, 2010 at 07:30 AM · camerasquaremini-map

Cannot create square Normalized Viewport Rectangle for MiniMap

Hi everyone. I am currently creating my first Unity game, which is pretty much the Car Racing game from the Multiplayer example but with heaps of extra maps and features. I want to create a MiniMap in the top-right hand corner of the screen and so far my Camera object looks like this:

Clear Flags: Depth-only Projection: Orthographic Normalized Viewport Rectangle: X: 0.7 Y: 0.7 W: 0.3 H: 0.3 Script: Spring Follow Camera Generic

I have two questions: 1. How can I make my viewport square without distorting the image. 2. How can I make the players look like small circles instead of weird coloured pixels?

My MiniMap doesn't follow the player, it shows the whole map and that is why the players are only pixels on the map.

THANKYOU!!!!

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 YoshieMaster · Oct 20, 2010 at 02:03 AM 0
Share

Thanks! I ended up setting the aspect of the camera to 1 and then using your code to figure out the rectangle. Setting the aspect turned out to be important as otherwise it was stretched. I will also be using the layers thing but have a new problem. From javascript, what can I add to draw a 3D model (a sphere) in a different layer?

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Jesse Anders · Oct 17, 2010 at 02:35 PM

The normalized viewport coordinates are mapped from the range [0, 1]x[0, 1] to the range [0, Screen.width]x[0, Screen.height].

Say the screen resolution is 800x600, and the normalized viewport rect is (.5, .5, .5, .5) - in other words, the upper-right corner of the screen in normalized coordinates (or maybe lower-right).

When mapped to screen space, this comes out as (x = 400, y = 300, w = 400, w = 300). As you can see, once mapped to screen space, the rectangle is no longer square. In order to get a square rectangle in screen space, you'll need to do the necessary arithmetic to compute a normalized rectangle that will be square once mapped to screen space.

This is off the top of my head and I may very well mess it up, but the following should compute a square viewport that's 1/4 the height of the screen and resides at the upper-right (or maybe lower-right) of the screen:

float aspect = Screen.width / Screen.height;
float height = .5f;
float width = height / aspect;
Rect rect = new Rect(1f - width, .5, width, height);

Again, that's off the top of my head, and may or may not correct.

For the 'distorted pixels' problem, I would try layers. Set up the minimap camera to ignore the layer that the actual car models are in. Then, attach graphics to the cars that are in a layer that only the minimap camera will render. The graphics could be (for example) large planes that are always upward-aligned and have some sort of appropriate icon on them. Set up the main camera not to render this layer. The 'icon' graphics will then not be visible to the main camera, but will be visible to the minimap camera. Provided you size them appropriately and use a fairly simple and clear graphic, I imagine this would give you the effect you're looking for.

Another option would be transform the car positions as necessary and render the icons in a different space. (They could probably even be GUI controls if you wanted.)

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

No one has followed this question yet.

Related Questions

Normalized view rects and render textures 1 Answer

Creating a simple mini-map? 2 Answers

Rendertexture + Normalized View Rect. 2 Answers

Is it possible to make a camera update only once every X seconds ? 2 Answers

How do I attach a Camera to a GUI (for a Mini map) 4 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