Head tracking gives strange rotation (Find Look At Rotation)


I’m trying to work on an efficient way of head tracking with only the Yaw (so the Pawn looks up and down). My code below does that, but for some reason if I get closer to the target it starts to invert, same goes for when I circle the target. Would love some help!

			FRotator MyHeadRot, EnemyHeadRot;
			FVector MyHeadVec, EnemyHeadVec;

			GetMesh()->GetSocketWorldLocationAndRotation("HeadFollowSocket", MyHeadVec, MyHeadRot);
			CurrentTargetActor->GetMesh()->GetSocketWorldLocationAndRotation("HeadFollowSocket", EnemyHeadVec, EnemyHeadRot);

			FRotator NewBlendRotation = UKismetMathLibrary::FindLookAtRotation(MyHeadVec, EnemyHeadVec);
			NewBlendRotation.Pitch = 0.0f;
			NewBlendRotation.Yaw = FMath::Clamp(NewBlendRotation.Yaw, -45.0f, 45.0f);
			NewBlendRotation.Roll = 0.0f;

			FTransform NewTransform = this->GetActorTransform().GetRelativeTransform(FTransform(NewBlendRotation, MyHeadVec, FVector(1.0f,1.0f,1.0f)));

			PawnAnimation->WSDK_Skeleton_HeadMotion = FMath::RInterpTo(PawnAnimation->WSDK_Skeleton_HeadMotion, NewTransform.Rotator(), DeltaTime, 2.0f);

Just don’t change the previous rotation if you get close.

float Distance = (MyHeadVec - EnemyHeadVec).Size();

if (Distance>100)

I hope it helps.
If you have a better implementation, please let me know.