Target box displaying wrong

Hi guys,
I have a very simple script that draws a “target box” on screen (and the box bounds an object like an enemy).
I was aware that a target behind the player shares the same screen coordinate of a target ahead and I solved the issue just by adding if (enemyShip.renderer.isVisible)
and everything works. Kinda.

Now the problem is that if the enemy ship is behind the player and between the player and the sun (directional light), the target box appears in front of me (even tho the enemyShip.renderer is NOT visible).
This problem happens only when the enemy, the player and the sun are on the same “line”.

Usual behaviour:

27460-right.png

Weird behaviour:

27461-wrong.png

I actually have no idea why it acts like this. Any suggestions?
Thanks in advance :wink:

My suggestion would be to simply move the directional light. Since it shines in a uniform direction, from an infinitely far away point, you can simply move the directional light object either far to the left or right of your scene, or move it above the scene.

Unless your problem is that if your directional light, enemy and player are all in the one parallel plane/line. Then, I’m not sure what to do.