Search Unity

Height and width (pixels ) vs X and Y (axis units)

Discussion in '2D' started by Brama, Jan 11, 2014.

  1. Brama

    Brama

    Joined:
    Jan 11, 2014
    Posts:
    1
    Hello,

    I created a player sprite and I don't want it to move any further than camera borders are. I can get Screen.width and Screen.height values but I don't know how to use those to reposition or make a comparison with translation.position.x nor .y nor .z. I know Screen.height and .width are integer values which we all know as pixels but i don't know how to make a connection with xyz axis units.

    How can I limit player sprite movement if I know dimensions of a screen?
     
  2. unitylover

    unitylover

    Joined:
    Jul 6, 2013
    Posts:
    346
  3. RedVonix

    RedVonix

    Joined:
    Dec 13, 2011
    Posts:
    422
    WorldToScreenPoint seems to work great in the editor but as soon as you get onto an iOS device its coordinates are offset rather badly. Seems to be a bug in Unity possibly?
     
  4. unitylover

    unitylover

    Joined:
    Jul 6, 2013
    Posts:
    346
    Maybe WorldToViewportPoint is better suited for your needs. It takes into account the viewport of the camera.