- Home /
OffScreen Effect
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
The only way I see to do this is to render a camera view in a screen texture. Unfortunately, this is a Unity pro only feature so if you don't have Unity pro you won't be able to do it like this.
Another way would be to just display that circle-like texture on the screen and then placing an actual 3d model on it, which shares the same model and animations as the offscreen model.
Thanks for the advice, but I think you missed the point. This is not what I am after. I have simple sprites rendered already (simple red triangles). I'm not trying to get the camera-circle effect. I am just trying to copy the position.
Oh okey, I thought you ment making your character appear as a picture on the screen when he's offscreen like it's done on ssbm
Answer by robertbu · Jan 26, 2013 at 08:34 PM
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: