Hi, all!
I am trying to achieve the offscreen indicator similar to that in Super Smash Bros (something we can all relate to, hopefully).

Check the upper left hand corner to see what I mean.
Luckily, I am not trying to get something that complicated. I have my sprites renderered, and I have the code to check if it is offscreen.
EDIT: I am trying to get the ‘position copying’ action, NOT the ‘player in the circle’ effect. I have simple symbols that I am using. I just want the circle to copy the player’s position but be clipped to the screen like the blue circles are.
I would just like to know how I might have the offScreen sprite copy the position of the offScreen player. (If Peach in the image were lower, the indicator would be as well).
Hopefully I have relayed my message well enough. I hope I can get this to work!
Thanks! - YA
For a 2D game, the indicator is fairly easy. Here is a starter script:
public class Tracker : MonoBehaviour {
public GameObject goToTrack;
void Update () {
Vector3 v3Screen = Camera.main.WorldToViewportPoint(goToTrack.transform.position);
if (v3Screen.x > -0.01f && v3Screen.x < 1.01f && v3Screen.y > -0.01f && v3Screen.y < 1.01f)
renderer.enabled = false;
else
{
renderer.enabled = true;
v3Screen.x = Mathf.Clamp (v3Screen.x, 0.01f, 0.99f);
v3Screen.y = Mathf.Clamp (v3Screen.y, 0.01f, 0.99f);
transform.position = Camera.main.ViewportToWorldPoint (v3Screen);
}
}
}
It used the fact that when you convert a world point to a viewport point, the values for x and y will be between 0 and 1 if the point is visible. You have to fudge the number a little, since this check will be for the position of the object and does not take into account the object’s size.
For 3D, things are more complicated. See this post for a starting point:
How To Make A 2D GUI Arrow Point At A 3D Object