RealDocs

UKismetMathLibrary::GetReflectionVector

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

Description

Reflects a direction vector across a surface normal, like a laser bouncing off a mirror. Equivalent to Direction - 2*(Direction dot SurfaceNormal)*SurfaceNormal.

Caveats & Gotchas

  • • SurfaceNormal should be a unit vector. Passing a non-normalized normal scales the reflected vector incorrectly — normalize it first with Normal() or use FHitResult.ImpactNormal which is already unit.
  • • This function and MirrorVectorByNormal perform the same mathematical operation. GetReflectionVector is the preferred name in modern UE usage and has the ScriptMethod alias 'MirrorByVector'; prefer it over MirrorVectorByNormal in new code.

Signature

static UE_INL_API FVector GetReflectionVector(FVector Direction, FVector SurfaceNormal);

Parameters

Name Type Description Default
Direction FVector Incoming direction vector (does not need to be normalized). —
SurfaceNormal FVector The normal of the surface to reflect across. Should be unit length. —

Return Type

FVector

Example

Ricochet projectile off a surface C++
void AProjectile::OnHit(const FHitResult& Hit)
{
    FVector NewDir = UKismetMathLibrary::GetReflectionVector(
        GetVelocity().GetSafeNormal(), Hit.ImpactNormal);
    ProjectileMovement->Velocity = NewDir * GetVelocity().Size() * Bounciness;
}

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.