Find Look at Rotation in C++

Hello fellow Programmers,

I came across a problem, when i tried to make a turret look at the player. Other post on the HUB was not helpful to me :frowning:
It was fairly easy in Blueprint.
My problem is that i cant acces the FindLookatRotation() function in C++.

void ATurretC::TickActor(float DeltaTime, enum ELevelTick TickType, FActorTickFunction& ThisTickFunction)
{
	if (PlayerInside)
	{
		FVector PlayerLoc = GetWorld()->GetFirstPlayerController()->GetCharacter()->GetActorLocation();
		FRotator PlayerRot = UKismetMathLibrary::FindLookAtRotation(this->GetActorLocation,PlayerLoc);
		FRotator NewRot = FMath::RInterpTo(StaticMesh2->GetComponentRotation(), PlayerRot, DeltaTime, 2);
	}
	else
	{
		// TODO, Set rot back to Default
		//RootComponent->SetWorldRotation(FRotator(0, 0, 0));
	}
}

Error: ‘FRotator UKismetMathLibrary::FindLookAtRotation(const FVector &,const FVector &)’ : cannot convert argument 1 from ‘overloaded-function’ to ‘const FVector &’
1> Reason: cannot convert from ‘overloaded-function’ to ‘const FVector’

Any other solution to replace UKismetMath Library?

Thank you all in advance,
szuecsg

1 Like

FRotator newrot = (PlayerLoc - StaticMesh2->GetComponentLocation()).Rotation();

This works fine.

4 Likes

Hmm… I think the error say you are passing the function an overloaded function instead of FVector.
The reason for that is that you are missing parenthesis after GetActorLocation at line 6.
Instead of:

FRotator PlayerRot = UKismetMathLibrary::FindLookAtRotation(this->GetActorLocation,PlayerLoc);

The correct line is:

FRotator PlayerRot = UKismetMathLibrary::FindLookAtRotation(this->GetActorLocation(), PlayerLoc);
5 Likes