# Pixels Moved in scene Transitions

Hello
I have a script in which at some point the camera translates a specified amount, hence the whole scene translates. I would like to know the number of pixels that the camera goes over in this translation.

I have been trying it with WorldToScreenPoint. However, after the translate it gives me zero values.

``````    Vector3 screenPos1 = cam.WorldToScreenPoint(target.position);
transform.Translate(1, 0, 0);
Vector3 screenPos2 = cam.WorldToScreenPoint(target.position);
float px = Mathf.Abs(screenPos2.x - screenPos1.x);
float py = Mathf.Abs(screenPos2.y - screenPos1.y);
float pz = Mathf.Abs(screenPos2.z - screenPos1.z);
``````

I have selected the target as the camera itself! which I know is not right. (both the cam and the target are the Main Camera in the scene)

Are there any other ways I can measure this?

Thank you

â€śPixels of camera movementâ€ť isnâ€™t even a well-defined concept unless your camera is Orthographic, in which case, you can calculate the answer based just on the camera properties (e.g. orthographicSize). What kind of camera do you have?

1 Like

Thank you JoeStrout. I didnâ€™t know about this property of the camera. My camera actually has perspective projection.

OK, so in perspective, the issue is not well-defined. What is a â€śpixelâ€ť? At what distance from the camera do you want to measure these pixels?

What is it youâ€™re actually trying to accomplish here?

1 Like

I see.
I am actually doing a cognitive study and I my experiment involves Unity and an EyeTracker. I was trying to find the visual angle (in degrees) of the scene the user is looking at. The formula is this:
theta = 2 * arctang ( pix-width / (2*viewDistance) )

so for one pixel width I do this:

``````pixWidth = 1/(Screen.dpi);
``````

and when there is a scene translation, I was thinking of calculating the number of pixels on the screen that the camera is translated for and multiply it by the size of one pixel on the display.

``````        float viewDist = 55; // in cm
float pixMovex = px * (pixWidth * 2.54f); // num of pixels moved * size of pixel in cm
float thetax = 2 * ((Mathf.Atan(pixMovex / (2 * viewDist))) * Mathf.Rad2Deg);
``````

I see. I think I would recommend keeping your camera position the same in all scenes (which you could ensure, for example, by making it a prefab, as long as you never move it in code). That eliminates that variable entirely.

Also, depending on what youâ€™re doing, consider using an Orthographic camera. That will allow you to establish a fixed relationship between units in world space, and pixels on the screen (which you can then convert to degrees of visual angle). With a perspective camera, of course, this relationship is much more complex â€” things closer to the camera appear larger on screen than things further away.