Unity’s screen point, viewport point and world point

Posted on

in

,

 While developing Error Hunter in Unity, I found out there were 3 ways to display a point on screen:

diagram demostrating screen points in Unity[clear]Screen point: The points are the pixel values. You can use Screen.width and Screen.height to get the full screen dimensions. Neat.

unity-viewpoint[clear] View Point: Here the screen width and screen height are always 1, and everything in between is a fraction. Since mobile devices come in all shapes and sizes, this is quite a good way to go about using view points too.

unity-worldpoint[clear]

….and then we have the World Point. It seems to have it’s own unique measurement. eg. when you use transform.position += transform.right; you move the object to the right by 1 amount of this special measurement. Also, I couldn’t find a way to get the screen width/height in this ‘world space’. Quite a headache.

So, world points suck and you shouldn’t use them right? Wrong! You can only move objects around in world space so everything has to be converted to that. Here’s what I did in Error Hunter:

Vector3 fullScreen = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width,Screen.height,10));

I made a screen point in the top right and then converted it into world point. This allows me to use things like

 if (aRect.transform.position.y>fullScreen.y) {}

to check if something is going off screen.

2 responses to “Unity’s screen point, viewport point and world point”

  1. anon Avatar
    anon

    Thank you. Glad I found this. This really helped me! Was clear and simple to help me understand Unity’s many systems of measurements.

  2. gizm0 Avatar
    gizm0

    This was a clear explanation.

    A little drawing is better than a long discourse.

    Thank you.

Leave a Reply to gizm0 Cancel reply

Your email address will not be published. Required fields are marked *

About me

Mark Wong is a front end developer with 10+ years experience. Most of his knowledge of HTML5, CSS and Js is self taught.

Calendar

March 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
25262728293031