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.
- Inner half of the radius, under 3 m, which is 25% of the area:
radius * randf()49.4% and 49.6%. The script 24.9% and 25.0%. - Outer ring from 5 to 6 m, 30.6% of the area:
radius * randf()17.3% and 16.8%. The script 30.9% and 30.4%. - The script's furthest point: 6.00 m, so the whole circle is used.
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
radius: the size of the area. Keep it equal to the warning circle the player sees.- For a ring, such as strikes around the player but never on them, pick the radius with
sqrt(randf_range(inner * inner, outer * outer))instead. - To check whether a character is inside the circle when the strike lands: who is inside an AoE attack circle. For a skillshot line or a slam rectangle: check it in the attack's own space.
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
- Turn a 2D character left without the flicker
- A line or rectangle attack that hits what the player sees
- A scare that plays once, and only for the player
- An attack that hits even when a frame is slow
- Growing one cloud or aura zone grows all of them
- A parry window that is the same length on every screen
- A pair of portals that sends you through once
- An expanding shockwave that hits each enemy once
- Explosion damage that walls block, on the frame it goes off
- A fire or poison zone that keeps hurting while you stand in it
- A spike trap that hits whoever is already standing on it
- Who is inside an AoE attack circle
- Block only attacks from the front
- A sword hitbox that hits each enemy once per swing
- Slows and roots that overlap
- Blink forward without going into or through walls
- Knockback that the walk code does not cancel
- Keep a pressure plate down while anything is still on it
- Refill the guard meter only after the hits stop
- Heal from the damage that actually landed
- Let the shield take what it can and pass the rest of the hit to health
- A saw blade that slides along its path at a steady speed
- Explosion damage that reaches big enemies
- A spinning laser that hits everything it sweeps over