Take a piece of string, stretch it tight between two points — that’s Euclidean distance. It’s the straight-line, “as the crow flies” distance between any two points in space. Named after the ancient Greek mathematician Euclid, it’s the most intuitive way to measure how far apart two things are.
How to calculate it
Think of it like the Pythagorean theorem from school — the one about right triangles.
In 2D (a flat surface), if point A is at (1, 2) and point B is at (4, 6):
- Horizontal gap:
4 - 1 = 3 - Vertical gap:
6 - 2 = 4 - Distance:
sqrt(3² + 4²) = sqrt(9 + 16) = sqrt(25) = 5
In 3D, you just add the third dimension:
d = sqrt((x2-x1)² + (y2-y1)² + (z2-z1)²)
In Unreal Engine, you don’t need to do this math yourself — just call FVector::Dist(A, B).
Why it matters for pathfinding
In A-star pathfinding, the algorithm needs a heuristic — a quick guess of how far the goal is. Euclidean distance is the most common choice because:
- It’s fast to compute — just some subtraction, multiplication, and a square root
- It’s always admissible — the straight line can never be longer than any real path through obstacles, so it never overestimates. This guarantees A-star will find the optimal path.
- It works in any dimension — 2D, 3D, doesn’t matter
The only downside: in grid-based pathfinding where you can only move along axes (no diagonals), Manhattan distance can be a tighter estimate. But for 3D flying AI where movement is unrestricted, Euclidean distance is the natural choice.