RealDocs

UKismetMathLibrary::Vector_ClampSize2D

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

Description

Returns a copy of a vector with its XY (2D) magnitude clamped between Min and Max. The Z component is unchanged. Useful for horizontal movement clamping in games where vertical velocity is controlled separately.

Caveats & Gotchas

  • Only the XY plane magnitude is clamped; Z is passed through as-is. Do not use this when you need full 3D speed clamping.
  • If the 2D component (XY) is near-zero length and Min > 0, the 2D direction is undefined and scaling may produce unexpected results.
  • In top-down or character movement scenarios, this is preferable to ClampVectorSize to avoid unintentionally scaling vertical velocity.

Signature

static UE_INL_API FVector Vector_ClampSize2D(FVector A, double Min, double Max);

Parameters

Name Type Description Default
A FVector The input vector.
Min double Minimum 2D magnitude.
Max double Maximum 2D magnitude.

Return Type

FVector

Example

Clamp horizontal velocity while preserving Z C++
FVector Vel = CharacterMovement->Velocity;
// Clamp XY speed to [0, 500], keep Z for gravity
FVector ClampedVel = UKismetMathLibrary::Vector_ClampSize2D(Vel, 0.0, 500.0);
CharacterMovement->Velocity = ClampedVel;

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.