UKismetMathLibrary::Vector_ClampSizeMax2D
#include "Kismet/KismetMathLibrary.h"
Access: public
Specifiers: staticUFUNCTIONBlueprintPure
Description
Returns a copy of a vector with its XY (horizontal) magnitude clamped to at most Max. Z is preserved unchanged. Useful for capping lateral movement speed without affecting vertical velocity.
Caveats & Gotchas
- • Only the XY plane magnitude is capped; Z passes through unchanged. Do not use this for full 3D speed capping.
- • There is no minimum bound for the 2D magnitude. Vectors with XY length already <= Max are returned unmodified.
- • Equivalent to A.GetClampedToMaxSize2D(Max) on an FVector instance.
Signature
static UE_INL_API FVector Vector_ClampSizeMax2D(FVector A, double Max); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| A | FVector | The input vector. | — |
| Max | double | Maximum 2D magnitude allowed. | — |
Return Type
FVector Example
Cap horizontal movement while allowing vertical jumps C++
FVector Velocity = CharacterMovement->Velocity;
// Horizontal speed must not exceed MaxWalkSpeed, but don't clamp Z (gravity/jump)
Velocity = UKismetMathLibrary::Vector_ClampSizeMax2D(Velocity, MaxWalkSpeed);
CharacterMovement->Velocity = Velocity; Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?