# Find Look at Rotation in C++

**URL:** <https://forums.unrealengine.com/t/find-look-at-rotation-in-c/279907>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [April 7, 2014, 8:28pm UTC](https://forums.unrealengine.com/t/find-look-at-rotation-in-c/279907 "2014-04-07T20:28:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![szuecsg\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@szuecsg\_1](https://forums.unrealengine.com/u/szuecsg_1)\
**Post date:** [April 7, 2014, 8:28pm UTC](https://forums.unrealengine.com/t/find-look-at-rotation-in-c/279907/1 "2014-04-07T20:28:20Z")

</div>

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 ☹  
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

---

<div class="post-metadata">

**Author:** ![szuecsg\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@szuecsg\_1](https://forums.unrealengine.com/u/szuecsg_1)\
**Post date:** [April 7, 2014, 9:02pm UTC](https://forums.unrealengine.com/t/find-look-at-rotation-in-c/279907/2 "2014-04-07T21:02:29Z")

</div>

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

This works fine.

---

<div class="post-metadata">

**Author:** ![avrahamy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@avrahamy](https://forums.unrealengine.com/u/avrahamy)\
**Post date:** [July 11, 2014, 8:40pm UTC](https://forums.unrealengine.com/t/find-look-at-rotation-in-c/279907/3 "2014-07-11T20:40:17Z")

</div>

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);

```

---

<div class="post-metadata">

**Author:** ![DjHamiiD](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DjHamiiD](https://forums.unrealengine.com/u/DjHamiiD)\
**Post date:** [May 6, 2024, 3:55pm UTC](https://forums.unrealengine.com/t/find-look-at-rotation-in-c/279907/4 "2024-05-06T15:55:10Z")

</div>

Hello !  
I think the problem is firstly coming from the fact that you are not actually calling the function `GetActorLocation()` because you have forgotten the parentheses.

Also, your implementation seem to be not the best way to implement a turret looking at the player (if i got it right). I would suggest to set the actor rotation to the rotation the `UKismetMathLibrary::FindLookAtRotation()` returns.

It would be in your case something like this :

```auto
FVector PlayerLoc = GetWorld()->GetFirstPlayerController()->GetCharacter()->GetActorLocation();
FVector TurretLocation = GetActorLocation();
SetActorRotation(UKismetMathLibrary::FindLookAtRotation(TurretLocation, PlayerLoc));

```
