Look at rotation c++

Hello. I need to rotate an actor to face the player, but I don’t know how to get the rotation. I have tried using the UKismetMathLibrary::FindLookAtRotation, but that gives me a linker error. Any help is appreciated, thanks.

You can get the look at rotation by this in c++

FRotator Rot = FRotationMatrix::MakeFromX(Direction).Rotator();

Direction is from Target to your Player.

What do you mean direction is from target to your player? Do you mean thats the direction you need to rotate?

yeah, the direction u want to look at, Direction = PlayerLocation - ActorLocation

I tried doing
PlayerRot = FRotationMatrix::MakeFromX(playerLoc - actorLoc).Rotator(); SetActorLocation(actorLoc); SetActorRotation(PlayerRot);

but that made the actor lean farther backwards the closer it got to the player.

oh ok coz of the different height of the 2 actor location, must project the Direction to ground, so something like this Direction = FVector(Direction.X, Direction.Y, 0);

Thank you! it worked.

Great Answer! You helped me as well.