I am using a single directional light in a scene and I want the light to always come directly from the position of the players camera so the lighting is constantly full illuminated directly in front of where the player is looking. Imagine the player is the sun.
Working Code
Here is what I used based on the accepted answers suggestion. Add a directional light to the scene in the editor and I set the directional light variable on the level script in the editor and store the variable in my LevelScriptActor class in C++. Here is the header:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Lighting")
ADirectionalLight* Sun;
On tick (or with a timer) I run this code that gets the rotation from my player (HMD in my case) and the target I want the light to point to.
APawn* Pawn = Cast<APawn>(UGameplayStatics::GetPlayerPawn(GetWorld(), 0)); //Get single player
if (Pawn)
{
FVector HMDLocation = Pawn->CameraComponent->GetComponentLocation();
FRotator TargetRotation = UKismetMathLibrary::FindLookAtRotation(HMDLocation, Planet->GetActorLocation());
Sun->SetActorRotation(TargetRotation);
}
That’s it. I have the directional light set to movement and I set the intensity and all that stuff in the editor. The code just grabs control of the location and sets its based on the character movement. Now I always have a lit scene as if the sun was coming from the character. For now I have shadows turned off. I’m not sure what kind of performance hit i’m going to take turning it on.