UKismetMathLibrary::RandomUnitVectorInConeInRadiansFromStream
#include "Kismet/KismetMathLibrary.h"
Access: public
Specifiers: staticUFUNCTIONBlueprintPure
Description
Returns a random unit vector uniformly distributed within a cone around ConeDir, drawn from a specific FRandomStream so the result is reproducible given the same seed.
Caveats & Gotchas
- • ConeDir does not need to be normalized on input — the underlying FRandomStream::VRandCone normalizes it internally — but passing a zero vector produces an undefined direction.
- • A ConeHalfAngleInRadians of 0 or less returns ConeDir unmodified rather than a randomized vector, since the underlying implementation only randomizes for angles greater than zero.
Signature
static FVector RandomUnitVectorInConeInRadiansFromStream(const FRandomStream& Stream, const FVector& ConeDir, float ConeHalfAngleInRadians) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Stream | const FRandomStream& | The random stream from which to obtain the vector. | — |
| ConeDir | const FVector& | The base center direction of the cone. | — |
| ConeHalfAngleInRadians | float | The half-angle of the cone, from ConeDir to its edge, in radians. | — |
Return Type
FVector Example
Deterministic shotgun pellet spread C++
FRandomStream SpreadStream(ShotSeed);
for (int32 i = 0; i < NumPellets; ++i)
{
FVector PelletDir = UKismetMathLibrary::RandomUnitVectorInConeInRadiansFromStream(SpreadStream, AimDirection, FMath::DegreesToRadians(5.f));
FireTrace(MuzzleLocation, PelletDir);
} See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?