pezzott1
(pezzott1)
16


UFUNCTION(BlueprintPure, Category="CustomFunctions")
static void F_YawToTarget(
const USceneComponent* start,
const USceneComponent* target,
float& YawDEG);
#include "CustomFunctions.h"
#include "Math/UnrealMathUtility.h"
void UCustomFunctions::F_YawToTarget(
const USceneComponent* start,
const USceneComponent* target,
float& YawDEG)
{
FVector dir = (target->GetComponentLocation() - start->GetComponentLocation()).GetSafeNormal();
float ForwardDotProduct = start->GetForwardVector() | dir;
float RightDotProduct = start->GetRightVector() | dir;
if (RightDotProduct > 0.f)
YawDEG = FMath::Acos(ForwardDotProduct) * (180.f) / PI * (-1.f);
else
YawDEG = FMath::Acos(ForwardDotProduct) * (180.f) / PI;
}
2 Likes