• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Cannot change camera position (2D) 1 Answer

Simultaneous Animation for an Object 0 Answers

Sprite appears on the opposite side of screen 1 Answer

Screen Points to construct a Rect (Not axis aligned) 0 Answers

Object jitters when camera is moving and is in the near? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges