Hi all, i would like to rotate my character to look at mouse pointer in a Top down game.
My code, actually, is that:
void ADeadNationPlayerController::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);
}
Called every tick. But doesn’t seems to work correctly. Atleast, seems fine untile the mouse pointer goes behind the character.
Thanks,
Davide.