RealDocs

UKismetMathLibrary::FindClosestPointOnSegment

function Engine Blueprint Since 4.0
#include "Kismet/KismetMathLibrary.h"
Access: public Specifiers: staticUFUNCTIONBlueprintPure

Description

Returns the point on a finite line segment closest to the given query point. If the perpendicular projection falls outside the segment, the nearest endpoint is returned instead.

Caveats & Gotchas

  • Clamps to segment endpoints — if Point is beyond either end you get SegmentStart or SegmentEnd back, not an extrapolated position. Use FindClosestPointOnLine for infinite extrapolation.
  • When SegmentStart equals SegmentEnd (zero-length segment), the function safely returns SegmentStart but silently degenerates to a point-vs-point distance.

Signature

static UE_INL_API FVector FindClosestPointOnSegment(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

FVector

Example

Snap a foot IK target to the nearest point on a ledge edge C++
FVector FootPos = GetMesh()->GetSocketLocation(FName("foot_l"));
FVector IKTarget = UKismetMathLibrary::FindClosestPointOnSegment(
    FootPos, LedgeStart, LedgeEnd);

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.