How to get the transform of the camera for line trace

I’m trying to get the start position of my line trace to be attached to the player camera. I have code setup that gets the rotation of the line cast, but its start position is relative to world coordinates rather than the camera’s.

FTransform CameraTransform = PlayerCamera->GetComponentTransform();

// The start position of the line trace
FVector Start = CameraTransform.TransformVector(FVector(0.0f, 0.0f, 100.0f));
// The end position of the line trace
FVector End = CameraTransform.TransformVector(FVector(1000.0f, 0.0f, 100.0f));

FCollisionQueryParams RV_TraceParams = FCollisionQueryParams(FName(TEXT("Trace")), true, this);
RV_TraceParams.bTraceComplex = true;
RV_TraceParams.bReturnPhysicalMaterial = false;

FHitResult RV_Hit(ForceInit);
GetWorld()->LineTraceSingleByChannel(RV_Hit, Start, End, ECC_WorldStatic, RV_TraceParams);

My assumption is that PlayerCamera->GetComponentTransform() is the problem, but I don’t know why or how. I’ve also tried PlayerCamera->GetSocketTransform(TEXT(“PlayerCamera”)), and the result was the same.

Here is a GIF of what’s going on. As you can see the Start position is at world space. How do I make it local space to the camera?

Thanks in advance to anyone who can help.

FVector End = Start + CameraTransform.TransformVector(FVector(1000.0f, 0.0f, 100.0f));

This should do the trick

Unfortunately this didn’t work, the start is still attached to the world transform.

I found the Answer.

FVector Start = CameraTransform.GetLocation();

The trace now starts at the camera. Start did need to be added to the end variable. So thanks to xSheim as I wouldn’t have know to do that.

I’m sorry, I didn’t understand the question. If your Camera is a component of the pawn, you could just get world location of it. Otherwise you should do this stuff (easier to show in blueprint, but should look nearly the same in C++):