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.