ViewportToWorldPoint / ScreenToWorldPoint not working with custom projection matrix
Hi,
I am trying to position an object such that it is fixed relative to the viewport. I use ViewportToWorldPoint and set the position of the transform inside Update().
Vector3 worldPoint = camera.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 1f));
dotTestTransform.position = worldPoint;
This works as long as I do not adjust the cameras projection matrix in a certain way. For example if I change the (0,3) entry of the projection matrix, which should correspond to a shift of the camera in x-direction, the position of the sphere changes.
Why is that and is it expected behaviour? To me it seems like ViewportToWorldPoint / ScreenToWorldPoint are not using the full custom projection matrix inside.
[1]: Test Scene to reproduce the behaviour, just play the scene and adjust M.E03
I am experiencing the same issue and am equally perplexed. I was also trying to use ScreenToWorldPoint passing in the screen corners in pixels (0,0) (screen.width, screen.height) and it seems to only work from the original position of the camera. but if you move the camera it continues to result in the same values from where the camera was originally located.
i.e. This always produces the same result no matter where the camera is. Confused by that. (this is in a 2D game)
Camera.main.ScreenToWorldPoint( new Vector3(Screen.width, Screen.height, Camera.main.nearClipPlane) )
Your answer
![](https://koobas.hobune.stream/wayback/20220612170103im_/https://answers.unity.com/themes/thub/images/avi.jpg)