FVector::Distance
#include "Math/Vector.h"
Access: public
Specifiers: static
Description
Returns the Euclidean distance between two vectors. Internally computes `(V2 - V1).Size()`. For performance-sensitive comparisons, prefer `DistSquared()` to avoid the square root.
Signature
static double Distance(const FVector& V1, const FVector& V2) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| V1 | const FVector& | First vector. | — |
| V2 | const FVector& | Second vector. | — |
Return Type
double Caveats & Gotchas
- • If you only need to compare distances, use `FVector::DistSquared()` to avoid the square root computation.
- • Also accessible as the global `FVector::Dist()` alias.
Example
Distance check C++
float D = FVector::Distance(ActorA->GetActorLocation(), ActorB->GetActorLocation());
if (D < 200.f)
{
// Within range
}
// Cheaper: compare squared distances
float Threshold = 200.f;
if (FVector::DistSquared(A, B) < Threshold * Threshold)
{
// Avoids sqrt
} See Also
Version History
Introduced in: 1.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?