1
\$\begingroup\$

I created a camera of the size of 480x854 as the project is meant for Android but whenever I try to position objects on the scene editor, their positions dont seem to be in pixels. It is like -10 y on the top and 10 y on the bottom of the camera. So what I want is to see and position the objects on the scene editor in pixels.

Thanks in advance.

\$\endgroup\$
  • \$\begingroup\$ You should avoid setup anything to fixed resolution cause there are a lot of devices running Android. At the moment I think most of them got 5" screens with at least 1920x1080 or something similar. You should focus on aspect ratio. Most devices are 16:10 or 16:9. \$\endgroup\$ – Paweł Marecki Jun 29 '16 at 12:42
  • \$\begingroup\$ Ok but how to position the objects in pixels and not in "Unity units"? \$\endgroup\$ – Panagiotis Iatrou Jun 29 '16 at 12:45
  • \$\begingroup\$ I think you can't. Maybe i'm wrong but whole unity works in unity units. Every single gameobject. You'll need some extension to calculate somehow unity units to pixel on specified camera. You have to remember that you can got more than one camera, so what than. My advice is you should accept unity units and keep that in mind during creating your game. \$\endgroup\$ – Paweł Marecki Jun 29 '16 at 12:50
  • \$\begingroup\$ Ok, thanks. Btw, is position in the scripts like transform.position.x calculated in pixels or unity units? \$\endgroup\$ – Panagiotis Iatrou Jun 29 '16 at 12:52
  • \$\begingroup\$ Everything is in unity units. You can calculate pixels like this: WorldToScreenPoint \$\endgroup\$ – Paweł Marecki Jun 29 '16 at 13:03
0
\$\begingroup\$

In world space everything is measured in default meter unit. Terrain, gravity, sound etc depend on it.

In device display those world space coordinates are converted to screen space coordinates.

So you can't place things in pixel. It's a variable depends on device. And world space unit is meter, you have to place things in world space. It's proven best that way. You don't want to develop a game just for one device display.

enter image description here

tansform.position.x is floating point number represents one portion of a 2D/3D vector which is a position vector of an object. These are calculated in world space in meter and projected in display screen in pixels. (If your camera is positioned in the origin in world space it should look like the image).

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ So, if I understood correctly...the game will automatically stretch according to device dimensions? \$\endgroup\$ – Panagiotis Iatrou Jun 29 '16 at 14:04
  • \$\begingroup\$ No. It will place things on a correct positions on display. If you place things in pixel unit in an imaginary engine your game is fixed for just one display resolution that you are working on. If your question was mutil resolution support than, you will have to handle things like UI for multiple resolution. Unity UI by default does that. For using same background for multiple resolution you have to layer things up and keep the aspect ratios in mind. \$\endgroup\$ – Sourav Paul Jun 29 '16 at 14:28
  • \$\begingroup\$ Yeah, but i tested the 480x854 version on my device(worked perfectly) and also tested the same on another devicr whose resolution was 1920x1080 and also worked perfectly. All the objects were perfectly aligned and the speed was the same. :/ \$\endgroup\$ – Panagiotis Iatrou Jun 29 '16 at 14:37
  • \$\begingroup\$ That was because you are using same aspect ratio, 480p, 1080p both are 16:9 or 9:16. But if you are using a background of 480x854 will see some starching issue or shrinked image in 1080p display. Use 10:16 or 3:4 aspect to see result (comman andorid and ipad aspect). Going to main question, the speed you calculated was in world space meter unit. It should be working perfect as they converted to screen space. If you were calculating let's say an object goes 20 pixel per second(what you wanted) than in 1080p display it will take more time to reach to a distance say end of screen. \$\endgroup\$ – Sourav Paul Jun 29 '16 at 14:58
  • \$\begingroup\$ Ok thanks. So now what am gonna search for is what to do at different aspects. \$\endgroup\$ – Panagiotis Iatrou Jun 29 '16 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.