FMath::PointDistToLine
#include "Math/UnrealMathUtility.h"
Access: public
Specifiers: static
Description
Returns the perpendicular distance from a point to an infinite line defined by an origin and a direction. An overload without OutClosestPoint is also available.
Caveats & Gotchas
- • The line is infinite in both directions — this is not a segment distance. Use PointDistToSegment if you need distance to a finite segment.
- • Direction does not need to be normalized; the function normalizes it internally. Passing a zero-length Direction is undefined and will produce NaN.
- • The [[nodiscard]] overload (no OutClosestPoint) was marked nodiscard in UE 5.x — be aware the compiler will warn if you call it but discard the result.
Signature
static CORE_API float PointDistToLine(const FVector& Point, const FVector& Direction, const FVector& Origin, FVector& OutClosestPoint) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Point | const FVector& | The point to measure distance from. | — |
| Direction | const FVector& | Direction of the infinite line. Does not need to be normalized. | — |
| Origin | const FVector& | A reference point on the line. | — |
| OutClosestPoint | FVector& | Receives the closest point on the line to Point. Omit with the two-param overload if you don't need it. | — |
Return Type
float Example
Check if an actor is within a beam's radius C++
FVector ClosestPt;
float Dist = FMath::PointDistToLine(
TargetActor->GetActorLocation(),
BeamDirection,
BeamOrigin,
ClosestPt
);
if (Dist < BeamRadius)
{
ApplyBeamEffect(TargetActor, ClosestPt);
} Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?