> For the complete documentation index, see [llms.txt](https://docs.quickclient.cc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.quickclient.cc/en/examples/player-radar.md).

# Player radar

A HUD radar that shows nearby players as dots.

A small square on the HUD where nearby players are marked with dots. The radar rotates together with the camera. The example shows how to draw with `Render2D`, use theme colors, work with entities and why it is better to get the entity list once per frame.

```java
package my;

import hex.script.api.ColorPicker;
import hex.script.api.Entity;
import hex.script.api.Render2D;
import hex.script.api.Script;
import hex.script.api.Slider;

public class PlayerRadar extends Script {

    private final Slider size = slider("Size", 70f, 40f, 160f, 5f);
    private final Slider range = slider("Range", 40f, 10f, 100f, 5f).postfix("m");
    private final ColorPicker enemy = colorPicker("Enemies", 0xFFFF3B30);
    private final ColorPicker friend = colorPicker("Friends", 0xFF57D977);

    @Override
    public String description() {
        return "Shows nearby players as dots";
    }

    @Override
    public void onRender2D(Render2D render) {
        if (!player().present()) return;

        float box = size.value();
        float x = 10f;
        float y = 10f;
        float cx = x + box / 2f;
        float cy = y + box / 2f;

        render.drawBlur(x, y, box, box, 4f, 1f, 8f, 0.6f, render.themeColor("rect"));
        render.drawClientOutline(x, y, box, box, 4f, 1f,
                render.fade(0), render.fade(90), render.fade(180), render.fade(270));
        render.drawClientRect(cx - 1f, cy - 1f, 2f, 2f, 1f, render.themeColor("text"));

        double scale = box / 2.0 / range.value();
        double yaw = Math.toRadians(player().yaw());
        double sin = Math.sin(yaw);
        double cos = Math.cos(yaw);

        for (Entity other : entities().players(range.value())) {
            double dx = other.x() - player().x();
            double dz = other.z() - player().z();
            double rx = dx * cos + dz * sin;
            double rz = dz * cos - dx * sin;

            float px = (float) (cx + rx * scale);
            float py = (float) (cy + rz * scale);
            if (px < x + 2f || px > x + box - 2f || py < y + 2f || py > y + box - 2f) continue;

            int color = other.friend() ? friend.value() : enemy.value();
            render.drawClientRect(px - 1.5f, py - 1.5f, 3f, 3f, 1.5f, color);
        }
    }
}
```

## How it works

**Rotating with the camera.** The offset to each player is rotated by the view angle, so "forward" on the radar always points up. `player().yaw()` returns degrees, so `Math.toRadians` is needed before the sine.

**Theme colors.** `themeColor("rect")` and `themeColor("text")` take colors from the current Quick theme, and `fade(0..270)` give four points of the moving gradient for the outline. This way the radar looks like part of the Quick interface rather than a separate overlay.

**Entities once per frame.** `entities().players(range)` builds a new array on every call. Calling it in a loop or twice per frame is extra work sixty times a second.

**Dots outside the edge.** The radar radius and the search radius are the same, but the diagonal of the square is longer than the radius, so the bounds still need to be checked.

**Everything in the render method.** All the calculations here are cheap, so they live right in `onRender2D`. If you needed a sorted list or a tab list lookup, it would be worth doing that in `onTick()` and storing the result in a field.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.quickclient.cc/en/examples/player-radar.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
