- Home /
Is there an alternative to Camera.WorldToScreenPoint or another way to solve this problem?
Hi all,
I'm using Camera.main.WorldToScreenPoint
to show an image on the canvas based on the user position in world space which is in turn based on the GPS signal. When zooming out, the image of the user disappears when the distance to the Camera get larger than somewhere above 1000. The exact distance varies depending on the supposed vertical location of the user image on the screen.
Does someone know an alternative to Camera.WorldToScreenPoint
or another way to solve this problem?
The specific code I use:
Vector3 userToScreen = Camera.main.WorldToScreenPoint(userIndicator); userIndicatorImage.transform.position = userToScreen;
I have looked into using the actual camera and world space matrices but can not come up with the right way to formulate the code to make it work. Can I perhaps see what Unity is doing behind the scenes when I execute Camera.WorldToScreenPoint
?
Kind regards,
Yorick
I thought it would not be a draw distance issue because the image is on the Canvas (which is set to "Screen - space overlay"). But it turned out the WorldToScreenPoint also returned a Z value and it seems that that value has to be below 1000 to make the image appear on the canvas.
I solved the problem by multiplying the Z value by 0.
userToScreen = Vector3.Scale(userToScreen, new Vector3(1, 1, 0));
Thank you very much!
It could be draw distance related, although I have always had to inverse the Y coords of WorldToScreenPoint to get it to work properly.
Have ou verified that the user indicator is at the correct position?
I verified it only by looking at it and seeing it placed in the exact spot I expected but there was a secret Z value which caused the issue
Your answer
![](https://koobas.hobune.stream/wayback/20220612094111im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Conversion from world to screen space not right? 1 Answer
How to render world space objects in screen space using Matrix ? 0 Answers
Worldspace canvas blocking input of Screen Space Overlay Canvas 0 Answers
Dragging panel(prefab) from screen space canvas to world space canvas and scaling to fit 0 Answers