UI Toolbox logoUI Toolbox
Support

CompassBar

A CompassBar is the strip at the top of the screen that shows the heading of the player, with the directions, notches, and an icon for each HudTarget at its bearing. Use it in an open world or a shooter, so the player knows where to turn.

A compass bar over a 3D scene, with markers for an enemy, an ally and an objectiveA compass bar over a 3D scene, with markers for an enemy, an ally and an objective

Video tutorial: World-space HUD. All videos: Video tutorials. Demo scene: CompassBarDemo.unity.

How to add a compass in UXML:

<tb:CompassBar style="width: 480px; align-self: center;" />

It shows every HudTarget whose ShowOn has Compass, with no code.

How to show more of the circle, with notches every 10 degrees and the distance under each icon:

<tb:CompassBar field-of-view="240" tick-step="10" show-distance="true" />

How to change the labels:

var compass = root.Q<CompassBar>();
compass.Labels = new List<string> { "N", "E", "S", "W" };
compass.Player = ship.transform;
Member Description
Camera Gives the player when Player is null and no target is the player. Null (the default) uses Camera.main.
Player The object whose heading the compass shows. Null (the default) uses the HudTarget with IsPlayer, else the camera.
Labels (labels) The labels around the circle, from north clockwise at equal steps. The 8 directions by default.
TickStep (tick-step) Degrees between two notches, at least 1. 15 by default. 0 draws no notches.
FieldOfView (field-of-view) The degrees that the width of the bar shows, from 30 to 360. 180 by default.
ShowDistance (show-distance) Shows the distance under the icon of each target. Off by default.
DistanceFormat (distance-format) The format of the distance, with the meters as {0}. {0:0} m by default. A malformed format logs one warning and falls back to the default.
ShowPathMark (show-path-mark) Marks the bearing of the next corner of the path that a Minimap shows. On by default.

Tips:

In the examples

Styling

Class Element
tb-compass-bar The bar: 40 px high, 200 px wide at least, a --tb-color-overlay background with --tb-radius-sm. It clips the labels and the icons at its edges.
tb-compass-bar__label A direction label: bold, --tb-color-text with an outline, near the top.
tb-compass-bar__distance The distance under an icon: --tb-font-size-xs, at the bottom.
Variable Description
--tb-compass-notch-color The color of the notches and of the heading mark. --tb-color-text-muted by default.
--tb-compass-icon-size The size of the target icons, in pixels. 16 by default.
--tb-compass-path-color The color of the path mark. --tb-color-warning by default.
--tb-color-hud-outline The color of the text outline of the labels. rgba(0, 0, 0, 0.8) by default.
/* A light compass with large icons */
.hud-root .tb-compass-bar {
    background-color: rgba(255, 255, 255, 0.2);
    --tb-compass-notch-color: rgb(40, 40, 40);
    --tb-compass-icon-size: 22;
}

The CompassBarDemo scene shows the heading and the notches, the bearings of raiders, an ally and a far shrine with distances, sets of labels, a route with waypoints and three looks.