Oh, ok. I didn’t realize the ‘you’ in that sentence was me.
Here’s an example to maybe get you pointed in the right direction. (This’ll be off the top of my head, so no guarantee I’ll get everything right.)
So you have the center of the screen, call it p1:
Vector2 p1 = new Vector2(Screen.width * .5f, Screen.height * .5f);
And you have the projected point of interest, p2. First, convert the line passing through these two points to parametric form, like this:
Vector2 origin = p1;
Vector2 direction = p2 - p1;
direction /= direction.magnitude;
Note that if you haven’t already removed from consideration entities that are visible onscreen or are behind the player, you’ll need to check the magnitude of ‘direction’ against an epsilon (small value, such as .01) first and bail if it’s below that threshold. (This will mean that the entity is more or less directly ahead of or behind the player, in which case the direction for the indicator can’t be uniquely determined.)
Now, you need a function to intersect your ray with a 2-d hyperplane (i.e. a line). Again, no guarantee I’ll get this right, but here goes:
bool IntersectLine(
Vector2 origin,
Vector2 direction,
Vector2 normal,
float distance,
ref Vector2 outP)
{
float denom = Vector2.Dot(direction, normal);
if (Mathf.Abs(denom) > .01) {
float numer = distance - Vector2.Dot(origin, normal);
float t = numer / denom;
if (t >= 0f) {
outP = origin + t * direction;
return true;
}
}
return false;
}
For the derivation of this algorithm, Google ‘ray plane intersection’. (In short, you plug the ray equation into the plane equation and solve for t.)
All that’s left is to determine the hyperplane normals and distances for the four edges of the screen. They are:
left: normal = (1,0), distance = 0
right: normal = (-1,0), distance = Screen.width
top: normal = (0,1), distance = 0
bottom: normal = (0,-1), distance = Screen.height
(Maybe top and bottom are reversed - I can’t remember which way the +y axis points in screen space in Unity.)