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.

1 Like

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.

1 Like

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.

Thank u, this is the simplest code i’ve found, it works for me.