360° offscreen indicator

Dear Unity dev community!

I try to achieve an offscreen indicator, which correctly works even when the indicator points to an object behind the player. And creating multiple offscreen indicators, when there are multiple objects behind the player. So for example if the user would rotate the camera perfectly horizontally from leftwards, the indicator should be at the same Y value on the right side, and when it’s totally behind the user, it should just flip to the left side.

I had two approach:
-using camera.WorldToViewportPoint, and it worked well, if the object was not too much far away from the viewport. But if I moved away much more, the Y value of the result Vector3 of WorldToViewportPoint went to infinity.
I’m using perspective camera, and I recognised it depends on the FOV value of the camera. But I don’t think I should modify or fixate the FOV because of this feature of the game.
I checked the solution with orthographic camera, and it worked well from a certain distance from the object. But even if I would create a script to change the size of the camera based on distance of the target, that shouldn’t be a solution.

-using GeometryUtility.CalculateFrustumPlanes, and using Plane.ClosestPointOnPlane(target), I placed the indicator on the plane, and if I would add an offset value, I could place the indicator a bit more inside into the view, away from the planes. But these planes are infinite, and the closest point on those planes won’t be always near the viewport.

I believe my first approach would be better, but I don’t know how to eliminate that Y going to infinite. First of all I don’t even understand why the Y goes to infinite. The point is reflected on the viewport, which never scaled down or anything. I found some examples on Youtube or other places, and I found they also do this badly (for example here:

)

How to eliminate the Y going to infinite?

Maybe try this tutorial:

@exiguous that was also badly working.
A correct approach was to use dot product. Will describe the actual solution later.