UKismetMathLibrary::Vector_BoundedToCube
#include "Kismet/KismetMathLibrary.h"
Access: public
Specifiers: staticBlueprintPure
Description
Clamps each component of a vector to lie within [-InRadius, InRadius], effectively constraining the vector to an axis-aligned cube centered at the origin.
Caveats & Gotchas
- • The cube is always centered at the origin. To clamp relative to a different center, subtract the center first, clamp, then add it back. Or use Vector_BoundedToBox for a non-origin-centered box.
- • This clamps per-axis independently — it does not project to the surface of a sphere. A vector like (InRadius, InRadius, InRadius) lands at the cube corner, not on a sphere surface. The resulting vector may be longer than InRadius.
Signature
static UE_INL_API FVector Vector_BoundedToCube(FVector InVect, float InRadius); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| InVect | FVector | The vector to clamp. | — |
| InRadius | float | Half-size of the axis-aligned cube (each axis is clamped to [-InRadius, InRadius]). | — |
Return Type
FVector Example
Limit input velocity to a cubic bound C++
FVector Velocity = Controller->GetInputVelocity();
FVector Clamped = UKismetMathLibrary::Vector_BoundedToCube(Velocity, MaxSpeed);
Character->GetMovementComponent()->Velocity = Clamped; Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?