ScreenToWorldPoint reversing values?

I’ve been trying to get world points from the camera but the x and y are flipped.

screenBounds = MainCamera.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, MainCamera.transform.position.z));

The camera’s z is at 0. I’ve tried changing to 1 to see if it changes anything.

Currently these lines return (2, 9) which doesn’t make sense.

Debug.Log(screenBounds.x);
Debug.Log(screenBounds.y);

Where is the MainCamera located in space? You haven’t gotten the dimensions/bounds of the camera, you’ve just gotten one point. If your camera is anywhere but (0,0,0), then you’re just outputting the top right corner.

Also, of note, your Z parameter doesn’t make sense. The Z of ScreenToWorldPoint is the number of units in front of the near clipping plane (e.g. in front of the camera), and sending in the camera’s own Z position is a weird number that doesn’t really correlate with anything. If Z is negative it could cause nonsensical results too - it’d be getting a point behind the camera, and with the camera frustum transformation, probably would have X and Y coordinates in weird spots too.

1 Like

What exactly are you trying to accomplish?

Passing the camera’s z coordinate in world space into that function doesn’t really make sense.

1 Like