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
7
Question by Matt 15 · Dec 04, 2010 at 07:27 PM · 2diphoneresolutionpixelaccuracy

World space to pixel space accuracy

I'm working on a 2D game, and looking through an orthographic camera. However, given the setup I have thus far, it seems that my final output is not as pixel perfect as the numbers I have entered. Here is an example. I have a grid, where cubes are 1.1 units apart from each other. Every few cubes, there is a larger space between them, that is undesired. Obviously since we have to shoot though the camera at objects existing in space, there is an eventual decision made by unity to round to the next pixel.

My question is, has anyone found a good setup for your camera to pixel ratio for iOS4s res of 960x640? so that a unit in unity is more mathematically equivalent to the pixels on screen?

My apologies if this didn't come out clearly, and thanks in advance!

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

Answer by d3coy · Jan 02, 2011 at 07:39 AM

You could just set up your orthographic camera to have the desired height by editing Size in the Inspector. For an orthographic camera, Size is half of the height of the camera in world units. If you wanted your camera 640 "pixels" tall, you'd set Size to be 320, and make sure all your objects have sizes specified in pixels.

I find that solution to be cumbersome, so what I do is just calculate the pixel ratio:

float pixelRatio = (camera.orthographicSize * 2) / camera.pixelHeight;

Now you can use this ratio to convert pixels to world units to properly size your objects:

someObject.width = pixelRatio * 64; // 64 pixels wide on screen

Comment
Add comment · Show 4 · 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 sacredgeometry · Jan 27, 2014 at 10:36 PM 0
Share

Amazing, just what I was looking for thanks.

avatar image brain56 · Apr 06, 2015 at 04:43 AM 0
Share

I love you.

avatar image firestoke · Nov 18, 2015 at 03:41 PM 0
Share

Dude, thanks a lot!!

avatar image AlterHaudegen · Feb 15, 2019 at 08:31 PM 0
Share

This saved me a lot of headache!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to letterbox the screen and have pixel perfection in a 2d game 0 Answers

Pixel Perfect on iPhone 0 Answers

Pixel perfect sprites being distorted only at odd-numbered resolutions 0 Answers

Pixel Perfect in different resolutions 0 Answers

iphone 2D settings 2 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