版本号:UE4.26
目的是:在C++中,获取所控对象位置指向目标位置的向量。
UKismetMathLibrary::FindLookAtRotation(ControlledPawn->GetActorLocation(), TargetLocation).RotateVector(FVector(1.f, 0.f, 0.f));
其中FindLookAtRotation获取Pawn到TargetLocation的旋转。
而RotateVector(FVector(1.f, 0.f, 0.f));是获取该旋转的向前向量,
代码来源为
AActor.GetActorForwardVector()->TemplateGetActorForwardVector()->RootComponent->GetForwardVector()
->GetComponentTransform().GetUnitAxis( EAxis::X )
FORCEINLINE FVector FTransform::GetUnitAxis(EAxis::Type InAxis) const
{
if (InAxis == EAxis::X)
{
return TransformVectorNoScale(FVector(1.f, 0.f, 0.f));
}
else if (InAxis == EAxis::Y)
{
return TransformVectorNoScale(FVector(0.f, 1.f, 0.f));
}
return TransformVectorNoScale(FVector(0.f, 0.f, 1.f));
}