- Home /
How can I find out a ViewportToWorldPoint position with a different orthographic size?
In the game you can zoom in and out between the orthographicSize of almost 0 and 8. I want to instantiate objects outside of the camera range as if the camera size was 8. I'm working in 2D so this shouldn't be hard but my equation doesn't work properly: vectorPos = Camera.main.ViewportToWorldPoint(Vector3.one) * (Camera.main.orthographicSize/maxCameraSize);
I want the vectorPos to be positioned at the top right corner of the screen as if the orthographicSize was 8 dispite of the actual size.
Answer by NoseKills · Sep 23, 2016 at 03:53 PM
When using orthographic camera, the calculation is quite easy even without helper methods.
Orthographic size is always half of screen height in world units, so:
var aspectRatio = (float)Screen.width / Screen.height;
var screenHalfHeight = Camera.main.orthographicSize;
var screenHalfWidth = screenHalfHeight * aspectRatio;
var depth = 1;
Vector3 topLeft = new Vector3(-screenHalfWidth, screenHalfHeight, depth);
This of course applies as such only if the camera is facing along the z-axis looking at the origin.
This is exactly what I was looking for, thank you very much :)