← Pixel Dreamer Studio

Random spots spread evenly inside a circle

Radius = radius x sqrt(randf()), not radius x randf().

Use radius * sqrt(randf()) for the distance from the centre and a random angle. With radius * randf(), in our Godot 4.7 test 49.4% and 49.6% of 20,000 points landed in the inner half of the radius, which is only 25% of the area, and the outer ring from 5 to 6 m, 30.6% of the area, got only about 17%. With the square root it was 24.9% to 25.0% inside and 30.4% to 30.9% in the outer ring.

The code

Put this node at the centre of the area and call random_point() each time you need a spot: where a meteor lands, where loot drops, where an enemy spawns. It returns a position on the ground in world space.

extends Node3D
## Picks random spots spread evenly inside a circle on the ground: meteor strikes, loot drops, spawn points.
## Put it at the centre of the area and call random_point().

@export var radius := 6.0


func random_point() -> Vector3:
	var r := radius * sqrt(randf())  # sqrt: the outer rings are bigger, so they need more of the points
	var a := randf() * TAU
	return global_position + Vector3(cos(a) * r, 0.0, sin(a) * r)

What we measured

A circle with a 6 m radius. 20,000 points with each method, with random seed 1 and again with seed 2. Two runs gave the same numbers.

Why a plain random radius clumps

A ring near the edge is much longer than a ring near the centre, so it needs more points to look as full. randf() gives every radius the same chance, which puts the same number of points on the short inner rings as on the long outer ones. The area inside a radius grows with the radius squared, so the square root undoes that and every square metre gets the same chance.

What to change

Warnings for where the strikes will land:AoE Telegraphs for Godot 4 has 35 attack warning indicators, including a meteor target, circles, donuts, cones and skillshot lines, with a signal at the exact moment the attack lands.

Tested in Godot 4.7 with the Compatibility renderer.

Ready-made: AoE Telegraphs for Godot 4 has 35 ready-made attack warning indicators, including a meteor target, circles, donuts and cones, with a signal at the moment the attack lands.

More how-tos for AoE Telegraphs for Godot 4: Particle ring standing up instead of flat

More how-tos: Hazards, traps and attacks