Take the offset from the player to each enemy, undo only the player's turn with d.rotated(Vector3.UP, -player.global_rotation.y), and draw Vector2(d.x, d.z) scaled to the radar, so the player's forward, -Z, points up. In our Godot 4.7 test, blips taken straight from global X and Z put an enemy 10 m straight ahead on the left of the radar once the player had turned 90 degrees left. The script kept it at the top, 41 px up on a 256 px radar that reaches 30 m.
The code
Add a Control with the same position and size as the radar picture, next to it rather than inside it, and attach this. Set player to the player, or to the camera in a first-person game, and add every enemy to the enemies group. blip_offset() gives where a blip goes, in pixels from the centre, if you would rather move icons than draw circles.
extends Control
## Draws enemy blips on a round radar. Up on the radar is where the player faces, and blips turn as the player turns.
## Put it over the radar picture with the same position and size, as a sibling, not a child of a spinning radar.
@export var player: Node3D # the player, or the camera in a first-person game
@export var range_m := 30.0 # metres from the centre to the rim
@export var group := "enemies" # every enemy is in this group
@export var blip_color := Color(1.0, 0.25, 0.2)
@export var blip_radius := 4.0
func _process(_delta: float) -> void:
queue_redraw()
func radar_radius() -> float:
return minf(size.x, size.y) * 0.5 - blip_radius
func blip_offset(world_pos: Vector3) -> Vector2:
var d := world_pos - player.global_position
d = d.rotated(Vector3.UP, -player.global_rotation.y) # undo only the turn: looking up or down does not move blips
var p := Vector2(d.x, d.z) * (radar_radius() / range_m) # the player's forward, -Z, points up on the radar
return p.limit_length(radar_radius()) # enemies out of range sit on the rim, not outside the radar
func _draw() -> void:
if player == null:
return
var centre := size * 0.5
for e in get_tree().get_nodes_in_group(group):
if e is Node3D:
draw_circle(centre + blip_offset(e.global_position), blip_radius, blip_color)
What we measured
A radar 256 px wide and 30 m to the rim, so a blip sits at most 124 px from the centre. We read the red pixels the script drew as well as the numbers. Two runs gave the same results.
- Facing the start direction, an enemy 10 m ahead: both ways 41 px up.
- After turning 90 degrees left, an enemy 10 m ahead: global X and Z drew it 41 px to the left. The script 41 px up. An enemy 10 m to the player's right: global X and Z drew it straight up, the script 41 px to the right.
- A camera looking up 45 degrees, an enemy 10 m ahead: the whole inverse transform,
global_transform.affine_inverse(), showed it 7.1 m away. Looking down 30 degrees, 8.7 m. The script 10.0 m both times. - An enemy 45 m ahead: with no limit the blip was 186 px from the centre, outside a radar that is 128 px from centre to edge. The script put it on the rim at 124 px.
- The same Control as a child of the radar picture: after the radar turned 90 degrees, the enemy ahead was drawn 41 px to the right. Next to the radar it stayed at the top.
Why the blips end up in the wrong place
World X and Z do not know which way the player faces, so blips from them make a map that always points the same way, while the player expects ahead to be up. The whole inverse transform does turn with the player, but it also undoes looking up and down, which tips the offset and makes enemies look closer. A flat radar only needs the turn around Y, and in Godot's default rotation order global_rotation.y is that turn by itself, even on a camera that also looks up or down.
Radar pictures that spin a sweep line usually rotate the whole node, and a child Control rotates with its parent, so blips placed inside it go round with the sweep.
What to change
range_m: metres from the centre to the rim. Enemies further away wait on the rim, in the right direction.blip_colorandblip_radius: the dot. For several kinds of blip, use one Control per group.- For a map that always points north, take out the
rotated()line.
Radar pictures to put it on: the Godot 4 Ready Kit is 9 products in one bundle, including the full VFX Collection and 124 Sci-Fi HUD Elements with 6 radars that spin a sweep, plus rings, reticles, target locks and gauges as Godot 4 scenes. The HUD pack is also sold on its own: 124 Sci-Fi HUD Elements.
Tested in Godot 4.7 with the Compatibility renderer.
Ready-made: Godot 4 Ready Kit is 9 products in one bundle: the full VFX Collection plus 124 Sci-Fi HUD Elements with 6 spinning radars, toon, ink wash, skies, PBR and tools.
More how-tos: UI and HUD
- A screen fade that finishes while the game is paused or slowed
- A hand of cards that always fits, without spreading out when it is small
- Edge markers that stay on the rim and point the true way
- A wrapped Label that is as wide as its text, up to a limit
- Big numbers with thousands separators, minus signs and all
- Show a 0 to 1 ratio on a progress bar, and fill a ring or gauge from the angle you want
- Blink or fade a tinted HUD element without losing its color
- Spin a HUD ring, radar or icon in place instead of around its corner
- Make buttons clickable again under a full-screen fade, transition or post-process ColorRect
- 9-slice window: corners that do not stretch
- Visual novel background: fill the screen, crossfade scenes
- Coins that fly to the HUD counter
- Floating damage numbers in 2D
- An icon over a 3D character's head, without the ghost behind the camera
- Drag a box to select 3D units, in any direction
- Pick the radial menu slot the mouse is pointing at
- Show a percent that never says 0% or 100% too early
- Type dialogue at the same letters per second on every line and every frame rate
- Place brush dots at the same spacing however fast the mouse moves
- Move a speedometer or gauge needle smoothly without cutting through the bottom
- A countdown that never shows 0 while time is left
- A coin counter that rolls up and lands on the real total