Hello, I am trying to draw UI elements over 3d world positions using the WorldToScreenPoint function. While this works normally using a Screen Space - Overlay type canvas, it doesn’t work with my World Space canvas.
Is there any way to make this work with a World Space canvas?
I’m trying to imagine this setup… is it for like a single partially-reflective HUD popup in a jet fighter, where a single worldspace canvas nearby is used to show highlights on multiple far-away targets?
If so I suppose it’s just a raycast thing:
get the ray of the camera for the target (worldspace to screenspace, screenspace to ray)
use that ray to cast at your canvas and decide if / where it hit, and put the UI item there
You can use RectTransformUtility to get details about the corners of RectTransforms.
Or probably just good old lerp from the corner coordinates in X direction, then Y direction
World space canvases operate in world space, not screen space (hence the name). There’s no reason to use WorldToScreenPoint. Just deal with world space coordinates directly.
Yes, exactly, the UI element im trying to display is a reticle for the aircrafts ballistic computer. I like the idea of a raycast going from my camera to the point im trying to point at. I’m gonna try doing that, thanks for the idea.
However I’m not sure if that will display correctly if the target 3d position is anywhere bellow my camera height, won’t the camera distance from my canvas (HUD) amplify the downwards position (of the reticle) too much? I’m just gonna try it and give an update then.