I trace a DebugLine from the character in this way
// Storing the Location and Rotation of the Character
FRotator PlayerRotation = GetControlRotation();
FVector RotXVector = PlayerRotation.Vector();
// START PLUG
FVector StartPlug = FVector(GetActorLocation().X, GetActorLocation().Y, GetActorLocation().Z + 77);
// END PLUG
int32 distance = 5000; // Maximum distance of the trace
FVector EndPlug = (RotXVector * distance) + StartPlug;
// Draws the red debug line
DrawDebugLine(GetWorld(), StartPlug, EndPlug, FColor(255, 0, 0), true, -1, 0, 0.7f);
Notice I add 77 to the GetActorLocation().Z in the StartPlug because my Camera is at 77 in the Z axis.
The fact you can see the beam in your first image means the ray is not starting at the camera’s position. Assuming it’s an FPS (“PC” is your player controller):
if ( PC && PC->PlayerCameraManager )
{
FVector StartPlug = PC->PlayerCameraManager->GetCameraLocation();
FVector RotXVector = PC->PlayerCameraManager->GetActorForwardVector();
...
The rest of your code can stay the same
If not an FPS or the camera is at an offset from where you want the beam to come out of, then the answer is different so specify if that’s the case.
I don’t know if you’re a single player game or not. You can search for how to get the appropriate player controller in a multiplayer game. In multiplayer it also depends if you’re doing the operations in the client or the server. More here:
So, it’s a multiplayer game.
Any weapon has its own Owner Character (replicated with RepNotify), I use that Owner to grab the PlayerController and shoot the DebugLine. When I shoot this is what happens on Server and Client