Game dev
Saved & recent

Distance

Related terms: magnitude, displacement, squared distance

How far apart two positions are. Subtract the positions to get the displacement from one to the other, then take its length. Use positions in the same coordinate space.

Useful for pickup ranges, nearby enemies and arrival checks. If you only need to test a radius, compare squared distance with squared radius to avoid a square root. Straight-line distance does not account for walls; pathfinding does.

dot(B - A, B - A) <= radius * radius

Further reading
Python documentation: math.dist: Euclidean distance
A B straight-line distance route around wall
The violet arrow shows straight-line distance from A to B. The dashed route goes around the wall.

View in the full Game dev collection