- Home /
ViewportToWorldPoint different resolutions
I am trying to display an object on the screen using an orthographic camera. The camera size is set to 100. I want the object to appear in the same area of the screen regardless of aspect ratio or resolution.
If I set my resolution to 854x480 the objects ViewPortToWorldPoint is .5719438 and displays where I want it.
If I then set the resolution to 1024x600 and set the objects position to the same ViewportToWorldPoint, it does not appear in the viewport at the same relative position. I thought that was the point of ViewportToWorldPoint?
I used this to set the position:
var p : Vector3 = cam.ViewportToWorldPoint (Vector3 (.57194,0,0));
transform.position = Vector3(p.x, transform.position.y, transform.position.z);
you can see the correct placement here:
and this is at 1024 width but with the same ViewportToWorldPoint position of .57194 it is now cut off on the left.
Is this the wrong approach for this? The size and scale work great, I just need the object to be in the right area of the screen depending on the resolution width. Thanks!
I notice that in your ViewportToWorldPoint call you aren't specifying a Z coordinate - I can't quite get my head around that with an orthographic camera but might that be causing you a problem? You aren't then positioning your graphic at the z you called ViewportToWorldPoint on.
Just a thought - might be totally irrelevant.
Thanks for the reply! Unfortunately even if I do supply a z coordinate it has the exact same results...like this:
var p : Vector3 = cam.ViewportToWorldPoint (Vector3 (.57194,2.645176,19.80699));
transform.position = Vector3(p.x, p.y, p.z);
One further random thought - the screenshots make the graphics look a different size - is this the case on the higher resolution? It it the size of the graphic and the change in aspect ratio that is causing the effect?
they are the same exact size, the only thing that changes is what is visible, my screenshots were hastily taken so they look like a different size. Thank you for your replies!!
Just thought i'd add some info: If the aspect ratio is 16x9 everything is fine. When I switch aspect ratios I want to change the position of this object automatically but I don't know the equation that would be needed to do such a thing. I thought that ViewportToWorldPoint was what I needed but I guess its not?