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
1
Question by x4000 · Mar 17, 2010 at 03:39 AM · camera2dtransform

Best way to set up a predictable, scalable viewport?

This one is more challenging, I think.

The Setup So Far

Basically what I am doing is setting up a 2D game with textured planes. The camera is orthographic, and that's no problem. The main thing is that, in the context of this specific game, I need for the camera to be fixed and never scroll, and then various sprites get drawn in camera coordinates, essentially. But since I'm rotating and blending these sprites, simply using DrawTexture is out (and that might have performance concerns anyway).

Mostly I have this working, but I'm trying to figure out the ideal way to handle the camera. There are basically two scaling components to this, and how they interact is not entirely clear to me:

  • First, you have the transform, with its positions and matrices and such which are all pretty familiar from my DirectX background.
  • Second, you have the orthographic size on the camera, which makes sense but is unclear what effect that then has on the overall transform of the camera.

Goal: Scaling, Bounded Viewport

Basically, my goal is to have basically a "virtual viewport" that is at max 1280x768, and at min 800x600. Anything under that would scale everything down (as it does already), and anything over that would either scale it up or would show a bounding area that is just empty. I could be fine with either approach, but am unsure about how to go about setting this up.

Local Vs World Vs Viewport Coordinate Conversions

Ideally I could then map 0,0 in world coordinates to one of the corners of the camera -- I'm used to it being top-left and having the vertical axis inverted, but I could work with whatever. Right now I have the camera centered at 0,0, however, and with the orthographic size being set to something like 768/2, that tends to lead to unpredictable scaling in world coordinates for me.

My thought was to just set a positional transform on the camera itself in addition to the orthographic size, and then just use local positional transforms on the various planes (which are parented to the camera), but this is not yielding the precision of results I would expect. On the vertical axis the plane positions are off by a little bit, and on the horizontal axis they are off by a lot.

Last Note

This is obviously a pretty complex question and I don't expect anyone to solve it in one go for me. But as this is something of a basic requirement for an easy-to-use fixed-camera 2D game environment (aka for puzzle games, etc), I figured someone else may have already basically solved this problem. Looking through public tutorials, etc, I don't see much.

If I can get a basic proof of concept of this sort of 2D setup figured out, I'll be sure to post the code since I know people are looking for various 2D examples (the shooter one is good, but doesn't address dynamic texture loading or how to handle a fixed-position camera at varying resolutions).

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
0
Best Answer

Answer by x4000 · Mar 18, 2010 at 12:38 AM

Well, I have wound up moving to Sprite Manager 2 for this, and have thus discussed that with the SM2 dev here.

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 lowbloodsugar · Mar 17, 2010 at 06:14 AM

Dude, I think you are over thinking it....

Navigate to: Edit->Project Settings->Player Settings

Expand "Supported Aspect Ratios".

Select the aspect ratio of your game. Uncheck every thing else, especially "Others"

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 x4000 · Mar 17, 2010 at 03:32 PM 0
Share

Not really helpful, but thanks. Aspect ratio is largely irrelevant, I care about literal pixels. Even if the aspect ratio is "correct" but is too large or small, this won't function as intended without various logic like what I'm discussing above.

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

Cannot change camera position (2D) 1 Answer

Quaternion Slerp Sanity Check 1 Answer

Looking for picture in picture effect using Canvas Elements and Cinemachine follow target 0 Answers

javascript to respawn player in 2d platformer not working 1 Answer

2D Sprite Scroller Shooter - Face Right When Standing still 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