← Pixel Dreamer Studio

Edge markers that stay on the rim and point the true way

Shrink the offset along its own line until it meets the edge, instead of clamping each axis.

Clamping x and y on their own turns a round minimap into a square one: a target off to the top right lands in the corner, outside the circle, and the icon points at the corner instead of the target. In our Godot 4.7 test, with targets 1,000 px away in 72 directions, the icon sat up to 38.1 px outside a 100 px minimap and pointed up to 38.5 degrees off. Arrows at the edge of a 1920 x 1080 screen pointed up to 49.3 degrees off. limit_length() for the circle, and scaling the offset until it meets the rectangle for the screen, gave 0 px outside and 0.0 degrees off.

The code

Save it as edge_marker.gd and load it with const EdgeMarker := preload("res://edge_marker.gd"). For a round minimap: icon.position = centre + EdgeMarker.on_circle(offset, 100.0, 8.0), where offset is the target's position from the player in minimap pixels and 8 is half the icon. For screen edge arrows: arrow.position = screen_centre + EdgeMarker.on_rect(offset, screen_size / 2, 24.0) and arrow.rotation = offset.angle(). EdgeMarker.is_off_edge() tells you when to swap the icon for an arrow.

extends RefCounted
## Keeps a marker for a far-away target on the edge of a round minimap or of
## the screen, pointing the true way. Clamping x and y on their own pushes the
## marker into the corners: outside a round map, and turned toward the corner.
##   icon.position = centre + EdgeMarker.on_circle(target_offset, 100.0, 8.0)
##   arrow.position = screen_centre + EdgeMarker.on_rect(target_offset, screen_size / 2, 24.0)
##   arrow.rotation = target_offset.angle()
## target_offset = where the target is from the player (or the screen centre),
## already scaled to the map's pixels.


static func on_circle(offset: Vector2, radius: float, margin := 0.0) -> Vector2:
	return offset.limit_length(radius - margin)  # same direction, never past the rim


static func on_rect(offset: Vector2, half_size: Vector2, margin := 0.0) -> Vector2:
	var h := half_size - Vector2(margin, margin)
	if absf(offset.x) <= h.x and absf(offset.y) <= h.y:
		return offset  # already inside: show it where it is
	var sx := h.x / absf(offset.x) if offset.x != 0.0 else INF
	var sy := h.y / absf(offset.y) if offset.y != 0.0 else INF
	return offset * minf(sx, sy)  # slide along the same line until it meets the edge


static func is_off_edge(offset: Vector2, radius: float, margin := 0.0) -> bool:  # swap to an arrow icon
	return offset.length() > radius - margin

What we measured

Targets 1,000 px from the player every 5 degrees, a round minimap of radius 100 px with an 8 px icon, and arrows on a 1920 x 1080 screen with a 24 px margin. Two runs gave the same numbers.

Why it happens

Clamping each axis on its own keeps every point inside a square. On a round map the corners of that square stick out past the circle by up to 41%, and a point pushed into a corner has a different angle from the target. limit_length() keeps the direction and only shortens the distance, so the point slides along the line to the target and stops at the rim. A screen is a rectangle, so the script works out which edge the line meets first and scales the offset to that edge.

What to change

Rings, radar and frames to put the markers on: 124 Sci-Fi HUD Elements has 124 sci-fi HUD elements, white on transparent PNG: rings, reticles, radar, gauges, graphs and frames, to tint any color.

Tested in Godot 4.7 with the Compatibility renderer.

Ready-made: 124 Sci-Fi HUD Elements has 124 sci-fi HUD elements, white on transparent PNG: rings, reticles, radar, gauges, graphs and frames, to tint any color.

More how-tos: UI and HUD