How do I get the world coordinates of the top left position of the camera?

So right now my code looks like this -

Vector3 p = cam.GetComponent().ScreenToWorldPoint(new Vector3(0 , 0, cam.nearClipPlane));

this gets the center of my screen. How would I start making measurements like getting the left side of the screen, right side of the screen, bottom, and top? I know I’d have to change the first to parameters in ScreenToWorldPoint but I have no idea what I should use.

That should be throwing an error, so I’m surprised you’re even getting values.

Screenspace is defined in pixels. The
bottom-left of the screen is (0,0);
the right-top is
(pixelWidth,pixelHeight). The z
position is in world units from the
camera.


Try this:

Vector3 p = cam.ScreenToWorldPoint(new Vector3(0, cam.pixelHeight, cam.nearClipPlane));

@jessespike thank you for your answer.

Vector3 p = cam.ScreenToWorldPoint(new Vector3(0, cam.pixelHeight, cam.nearClipPlane));

but instead of ScreenToWorldPoint ScreenToViewportPoint and it works for me.

Vector3 cameraPosition = Camera.main.ScreenToViewportPoint (new Vector3 (0, Camera.main.pixelHeight, 0));

Above is the example of my code.

OMG AT LAST! You’d think all you need to do is feed coordinates to ScreenToWorldPoint using the scene camera… but NOOOOOOOOOOOOOO.

Thank you.