I want to share my code about this challenge.
My code works well, but I want to hear any other suggestions or improvements.
void UTankAimingComponent::MoveTurretTowards(FVector HitLocation)
{
FRotator TurretRotator = Turret->GetForwardVector().Rotation();
FVector AimDirection = HitLocation - GetOwner()->GetActorLocation();
auto AimAsRotator = AimDirection.Rotation();
FRotator DeltaRotator = AimAsRotator - TurretRotator;
float RelativeSpeed = DeltaRotator.Yaw;
if (RelativeSpeed > 180.f)
{
RelativeSpeed -= 360.f;
}
Turret->Rotate(RelativeSpeed);
}