WorldToScreenPoint results are off, but watch what happens when I change projection mode during runtime
I am trying to do a quite a straightforward thing - to render a 2D rectangle above the 3D object (health bar) in the 3D space using the Canvas set to Screen Space - Overlay, by mapping the 3D object transform to screen point using the WorldToScreenPoint()
method. My camera is in the 3rd person mode - slightly off to the right and to the top and angled down.
The results are off - the rectangle is rendered near the 3D object, but not quite on its pivot center. When I move the camera, it "dances" around the object, the further the camera is, the more it "dances" around the object.
BUT, when I run the scene and then change the main camera projection mode from Perspective to Orthographic and then flip it BACK to Perspective, all rectangles anchor themselves automagically to the correct pivot centers and stay there, no matter how the camera moves.
I am confused... what could be the reason for such a behavior? How best to address this problem?
Your answer
Follow this Question
Related Questions
Drag and Stay(Fly) 0 Answers
Rendering a Canvas as Screen Space - Camera - Google Cardboard 0 Answers
click area is moved when camera is rorated 0 Answers
2d unity game Camera issue 0 Answers
getting -2 instead -1 0 Answers