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.
Answer by Jessespike · Dec 16, 2015 at 08:19 PM
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));
Answer by kartikips · Feb 16, 2017 at 07:13 AM
@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.
Answer by tcz8 · Oct 30, 2021 at 03:50 PM
OMG AT LAST! You'd think all you need to do is feed coordinates to ScreenToWorldPoint using the scene camera... but NOOOOOOOOOOOOOO.
Thank you.
Your answer
Follow this Question
Related Questions
Camera registering it is at correct position when it isn't 0 Answers
Get Vector3s in range 1 Answer