0
\$\begingroup\$

Is there any way available to convert screen space into view space as like in the following figure:

enter image description here

\$\endgroup\$
2
  • \$\begingroup\$ So just to clarify, from the last image (right most) to the middle one? \$\endgroup\$
    – user35344
    Dec 23, 2016 at 11:59
  • \$\begingroup\$ yes as name given below \$\endgroup\$ Dec 23, 2016 at 12:00

2 Answers 2

1
\$\begingroup\$

Assuming that you know the values of Camera.pixelWidth and Camera.pixelHeight, you can get from the last picture to the middle one by simply dividing your ScreenSpace coordinates respectively by Camera.pixelWidth and Camera.pixelHeight.

Vector2 screenSpacePosition = new Vector2(100, 100);
Vector2 viewportSpacePosition = new Vector2(screenSpacePosition.X / Camera.pixelWidth, screenSpacePosition.Y / Camera.pixelHeight)
\$\endgroup\$
0
\$\begingroup\$

Can't you just use Camera.ScreenToWorldPoint or Camera.WorldToScreenPoint? As you can guess from methods names, they are transforming screen position to world position, and vise versa.

The only thing you need to take into account is Z axis, which will be same to Z value of camera position.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .