UKismetMathLibrary::GetPointDistanceToSegment
#include "Kismet/KismetMathLibrary.h"
Access: public
Specifiers: staticUFUNCTIONBlueprintPure
Description
Returns the shortest distance from a point to a finite line segment, clamping to the nearest endpoint when the perpendicular projection falls outside the segment.
Caveats & Gotchas
- • Always returns a non-negative float with no directional information. If you need to know which side of the segment the point is on, retrieve the closest point with FindClosestPointOnSegment and compute the signed offset yourself.
- • For a zero-length segment (start == end), the result safely degenerates to FVector::Dist(Point, SegmentStart), but no warning is issued.
Signature
static UE_INL_API float GetPointDistanceToSegment(FVector Point, FVector SegmentStart, FVector SegmentEnd); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Point | FVector | The query point. | — |
| SegmentStart | FVector | Start of the segment. | — |
| SegmentEnd | FVector | End of the segment. | — |
Return Type
float Example
Trigger a trap when the player comes within range of a wire C++
float Dist = UKismetMathLibrary::GetPointDistanceToSegment(
GetPlayerCharacter()->GetActorLocation(), WireStart, WireEnd);
if (Dist < TriggerRadius) { ActivateTrap(); } Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?