Hello.
I have an actor what follows the related actor with his head facing when. The problem is; when I rotate by yaw the actor completely, it rotates with the right angle, but while when I rotate only the component I want, it rotates with a plus or minus 90 degree deviation.
FRotator AFollowHeadActor::DetectLookAngle(const AActor* Player) const
{
const FRotator LookAtRotation = UKismetMathLibrary::FindLookAtRotation(FollowingHead->GetComponentLocation(),
Player->GetActorLocation());
const float DeltaTime = UGameplayStatics::GetWorldDeltaSeconds(GetWorld());
const FRotator SumRotation = UKismetMathLibrary::RInterpTo(FollowingHead->GetComponentLocation(),
LookAtRotation, DeltaTime, 3.0f);
const FRotator UltimateRotation = UKismetMathLibrary::MakeRotator(0.0f, 0.0f, SumRotation.Yaw);
return UltimateRotation;
}
First of all, the detection timer starts to work when the sphere is overlapped, and after a certain distance the head rotates.
void AFollowHeadActor::FacePlayer()
{
if (bShouldRotate)
{
if (IsValid(PlayerCharacter)) FollowingHead->SetWorldRotation(DetectLookAngle(PlayerCharacter));
}
}
There must be a place I overlooked for this code to work properly. Can anyone help?