FMath::LineExtentBoxIntersection
#include "Math/UnrealMathUtility.h"
Access: public
Specifiers: static
Description
Performs a swept-box versus axis-aligned box intersection test and returns the hit location, normal, and parametric hit time. This is the building block for AABB-vs-AABB sweep queries.
Caveats & Gotchas
- • This is a swept box (Minkowski sum) test, not a ray-box test. Passing FVector::ZeroVector as Extent degenerates to a segment-box test but is less efficient than LineBoxIntersection.
- • HitTime is in the range [0, 1] where 0 is the Start and 1 is the End. If the function returns false the output parameters are undefined — always check the return value first.
Signature
static CORE_API bool LineExtentBoxIntersection(const FBox& inBox, const FVector& Start, const FVector& End, const FVector& Extent, FVector& HitLocation, FVector& HitNormal, float& HitTime) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| inBox | const FBox& | The box to test against. | — |
| Start | const FVector& | Start point of the swept box. | — |
| End | const FVector& | End point of the swept box. | — |
| Extent | const FVector& | Half-extents of the swept box. | — |
| HitLocation | FVector& | Output world-space location of the first contact point. | — |
| HitNormal | FVector& | Output normal of the box face that was hit. | — |
| HitTime | float& | Output normalised time [0,1] along the sweep at which intersection occurs. | — |
Return Type
bool Example
Sweep a box along a movement vector C++
FBox WorldBox = MyActor->GetComponentsBoundingBox();
FVector MoveStart = MyActor->GetActorLocation();
FVector MoveEnd = MoveStart + Velocity * DeltaTime;
FVector BoxHalfExtent(32.f, 32.f, 64.f);
FVector HitLoc, HitNorm;
float HitTime;
if (FMath::LineExtentBoxIntersection(WorldBox, MoveStart, MoveEnd, BoxHalfExtent, HitLoc, HitNorm, HitTime))
{
// Respond to collision at HitLoc
} Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?