How to make a 2D Horizontal Compass?

Hi guys.

I'm trying to make a compass system similar to the compass the player sees later in Half-Life 2: Episode 2, which is the horizontal bar at the bottom of the screen with the texture that scrolls as the player looks around. I've been spending all day trying to figure out how to replicate this in Unity to no solution.

Does anybody know how to make this?

1 Answer

1

I did one that is like this, but it is 3d - I made a cylinder, wrapped it with a texture, stuck it way down below the terrain with a camera aimed at it that was set to clip everything except the cylinder's layer.

There is a very simple script on the cylinder that rotates it in tandem with the main camera.

The end result is a rectangular strip where the cardinal directions scroll left or right as the main camera turns.

here's the script:

`
function Start () {
    mainCamera = GameObject.FindWithTag("MainCamera");
}

function Update () { normRot = Mathf.Abs(mainCamera.transform.eulerAngles.y); if (normRot > 360) { normRot = normRot % 360; } transform.eulerAngles.y = normRot - 180; // because we look at the "back"

}

`

The 2 variables need to be defined before the start function. and you should tag your "Main Camera" as "MainCamera". var mainCamera : GameObject; <----------var1 var normRot : float; <-----------var2 function Start () { mainCamera = GameObject.FindWithTag("MainCamera"); } function Update () { normRot = Mathf.Abs(mainCamera.transform.eulerAngles.y); if (normRot > 360) { normRot = normRot % 360; } transform.eulerAngles.y = normRot - 180; // because we look at the "back" }