- Home /
WorldToScreenPoint and enemy target issue
Hello, I have a question about Camera.WorldToScreenPoint.
I actually want to draw a "target box" around the enemy. The canvas with the box image is a prefab, and the enemy has a script that instantiates the canvas as child of the enemy itself (not the best way but I'll keept it this way for the moment).
Now the 1st problem is: since I use WorldToScreenPoint to translate the 3D position of the enemy into the 2D position on screen, the Z coordinate is missing and I see 2 target boxes, one around the enemy and the other one on the opposite side of my view. How can I avoid that? Should I deactivate/hide the canvas when the enemy renderer isn't visible? Or is the a better way to do that?
2nd problem: at a certain distance, the target box disappears even if the enemy is still visible. I'm definitely below the far clipping plane... so, why is it happening?
Thank you in advance. :)
Answer by U2-84 · Sep 10, 2021 at 07:14 PM
So, I tried to hide the target box when the enemy is not visible (using Renderer.isVisible). I can't get it to work using HDRP. It looks like there's always a camera seeing the object (I knew it does that in the editor, but in my case it does that in the build as well), so the Renderer.isVisible is always "true" and the target box never disappears. Tried it on a simple Built-in render pipeline project and it works. Any ideas? Thank you in advance.
Your answer
Follow this Question
Related Questions
Minimap blib icon error 1 Answer
How to create Enemy Health Bar ? 4 Answers
Radar Map Blip.......................... 1 Answer
Help positioning an object on a 2D plane 1 Answer
Make HUD to show object direction 0 Answers