- Home /
Question by
nagl23 · Jul 29, 2019 at 01:28 PM ·
camerascreenorthographicorthographic cameraworldtoscreenpoint
How to make WorldToScreenPoint work with an orthographic camera?
I'm trying to place a GUI.Label
over objects and I'm using an orthographic camera to look at the scene.
My code:
Vector3 screenPos = Camera.main.WorldToScreenPoint(position);
GUI.Label(new Rect(screenPos.x, screenPos.y, 100, 20), "Hello World!");
It seems that Camera.main.WorldToScreenPoint(position)
line returns a result that's not valid (it works only with perspective camera). The point on screen is correct on X axis (left-right) but Y axis (top-down) it's off.
How much it's off depends on target and camera world positions, but not on camera size (X on the screen is still correct after manipulating orthographic camera size).
What calculations needs to be done here to correctly place the label?
Comment