I am creating a top-down game in which the character is controlled via WASD and the rotation is based on the current mouse location. I cannot figure out how to convert the current mouse location to some sort of FRotator or FQuat.
My current thought process:
I know the player will always be located in the center of the screen. I would need to get the direction that the player is facing on the X-axis and use simple Trig to determine the angle based on the mouse location.
Unfortunately I do not know how to do this. The documentation I am finding seems largely based on UnrealScript and Unreal 3. Any help would be greatly appreciated.
EDIT: Added code used in solution.
void RotateToMouseCursor() {
// Get current mouse rotation
FVector mouseLocation, mouseDirection;
this->DeprojectMousePositionToWorld(mouseLocation, mouseDirection);
// Get local reference to the controller's character and its rotation
ACharacter *currentChar = this->GetCharacter();
FRotator charRotation = currentChar->GetActorRotation();
// Get the rotation of the mouse direction
FRotator targetRotation = mouseDirection.Rotation();
// Since I only want to turn the character relative to the ground,
// the Yaw is the only change needed.
FRotator newRot = FRotator(charRotation.Pitch, targetRotation.Yaw, charRotation.Roll);
currentChar->SetActorRotation(newRot);
}
