0
\$\begingroup\$

I am new to unity3d, Right now i am adding a cube as game object with coordinate 0,0,0 But when i run it on android device Iam facing 2 problem a) Coordinate system of unity3d are different from coordinate system of device, For device top left is 0,0 but for unity center of the screen is 0,0. How to fix that mismatch or i need to multiply with some factor to make it work.

b) Iam moving the object on x-axis this is what iam doing for moving object on x-axis

if(xback){
     xaxis+=(2*Time.deltaTime);
     if(xaxis >Screen.width/2){
      xback = false;
      }
     }
else if(!xback){ 
     xaxis-=(2*Time.deltaTime);
     if(xaxis<=-(Screen.width/2)){
      xback = true;
  }
 }

Vector2 temp = transform.position; 
temp.x = xaxis;
temp.y = yaxis; 
transform.position = temp;

But the problem iam facing is as soon as my xaxis equals 9 it touches the right of screen and then it get out of screen, so iam little bit confuse is unity3d pixel system is different from the one on device, because iam moving the cube by one pixel every time but movement is not equal to 1 pixel of device. so i want to know is pixel system of unity is different from pixel system of android or iam doing something wrong.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Your confusion likely stems from this: you are thinking in terms of pixels, and Unity (or any 3D libraray) is not. In order to make best use of Unity, you will need to learn the math behind 3D graphics. \$\endgroup\$ Mar 5, 2014 at 12:18

1 Answer 1

3
\$\begingroup\$

Unity (or any other 3D engine i believe) is not using pixels for positioning objects in space (maybe mostly because there is no Z axis in pixels and also because it brings thousands of other issues)

Unity uses Unit system (i personally see it as metric) you should take the unit cube as one meter, this means few things :

  • The pixel you see on screen cannot be naturally matched to Unity coordinates (and vice versa)
  • You need to calculate the report screen to World and World to Screen to find out those relatives positions
  • Gladly Unity has a function for you which do the job : Camera.ScreenToWorldPoint

And also those :

\$\endgroup\$
1
  • \$\begingroup\$ yaa it work for me :) \$\endgroup\$ Mar 11, 2014 at 9:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .