UKismetMathLibrary::RandomUnitVectorInConeInRadians
#include "Kismet/KismetMathLibrary.h"
Access: public
Specifiers: staticUFUNCTIONBlueprintPure
Description
Returns a random unit vector within a symmetric cone around ConeDir, with uniform distribution on the sphere surface inside the cone.
Caveats & Gotchas
- • ConeHalfAngleInRadians should be in [0, PI]; values outside this range produce undefined behavior. For full-sphere scatter, use RandomUnitVector directly.
- • Not thread-safe (NotBlueprintThreadSafe); uses the global FMath random state. For deterministic results, use a seeded FRandomStream.
Signature
static UE_INL_API FVector RandomUnitVectorInConeInRadians(FVector ConeDir, float ConeHalfAngleInRadians); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| ConeDir | FVector | Center direction of the cone. | — |
| ConeHalfAngleInRadians | float | Half-angle of the cone from its axis to its edge, in radians. | — |
Return Type
FVector Example
Randomize bullet spread within a 5-degree half-angle C++
FVector AimDir = GetActorForwardVector();
float HalfAngle = FMath::DegreesToRadians(5.f);
FVector BulletDir = UKismetMathLibrary::RandomUnitVectorInConeInRadians(AimDir, HalfAngle);
SpawnProjectile(GetActorLocation(), BulletDir); See Also
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?