- Home /
How do I convert a point in the world to coordinates on a world space canvas?
Hello Everyone,
I've got quite the stumper today (for me anyway). I need to be able to place an image on a canvas to mark where something in the world is. And since I am working in VR, the canvas has to be in world space mode.
I've got the code below which almost works, however it is very.. floaty.. it will be on the target if I am looking directly at it, however when you look away it drifts off the target in the opposite direction you look. A cool effect, but not what I need.
Here is the Code:
screenPos = cam.WorldToScreenPoint(worldPos);
canvasPos = new Vector3(screenPos.x - cam.pixelWidth/2, screenPos.y - cam.pixelHeight / 2, transform.localPosition.z);
transform.localPosition = canvasPos;
The canvas is directly in the center of the screen, and the image (which the script is attached to) is anchored to the center of the canvas.
Any ideas on how I can fix this?
Image of drifting (aimed at the corner of the terrain): https://i.imgur.com/EGwFYaX.gifv
Unity 2017.3, OpenVR/SteamVR, VRTK, Windows 10 x64, WMR
Your answer
Follow this Question
Related Questions
Strange UI Button hover offset when using Worldspace Canvas in VR 4 Answers
How to make a world canvas visible only from front side in a VR game ? 0 Answers
UI canvas attached to vive controller disappears after first run in editor on vive 0 Answers
World Space UI as an in-game computer screen! 0 Answers
No World Space Canvas render with Cardboard Distortion Correction: Unity 1 Answer