Try using the Component location instead of a empty socket location. My guess is GetSocketLocation("") is returning a zero vector (0,0,0), causing an issue with the trace start location.
You don’t want to use Component Location if you’re trying to get the camera location. There’s a helper method called GetPlayerViewPoint that will get you the camera position/rotation if using a first person camera.
I have tested this on 4.14.3 and 4.16.2 and both versions give me the same outcome.
I have tried two projects on 4.14.3 and two projects on 4.16.2 and it is always the same.
I have also tried to recreate this in blueprint and it gives the same outcome on that as well.
When the ray-cast starts it is in a straight line from the camera, but overtime the ray-cast starts to arc upwards i dont know what is making this happen.
The image is blurry but you can still see what is happening, The blue line is how the ray-cast is meant to look. The red line is the ray-cast.
Here is how I would setup a trace for a FPS weapon tracing from the center of the camera, outwards:
void AFPSExample_Character::Shoot( )
{
APlayerController *MyController = Cast<APlayerController>(GetController( ));
check(MyController);
FVector CameraLocation;
FRotator CameraRotation;
MyController->GetPlayerViewPoint(CameraLocation, CameraRotation);
check(CameraLocation != FVector::ZeroVector);
FVector StartTraceLocation = CameraLocation;
FVector EndTraceLocation = CameraLocation + (CameraRotation.Vector( ) * 65538.f);
FHitResult Hit;
FCollisionQueryParams TraceParams( FName( TEXT("Teleport Trace")), true, this );
if( GetWorld( )->LineTraceSingleByChannel(Hit, StartTraceLocation,EndTraceLocation,
ECC_WorldStatic, TraceParams))
{
UKismetSystemLibrary::DrawDebugLine(GetWorld( ), StartTraceLocation, EndTraceLocation, FLinearColor::Red, 12.f, 3.f);
UKismetSystemLibrary::DrawDebugSphere(GetWorld( ), Hit.ImpactPoint, 24.f, 8, FLinearColor::Yellow, 12.f, 3.f);
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Shoot trace failed!"));
// Case where player was probably aiming into the sky and didnt hit anything "world static".
// If needed, can use EndTraceLocation as point where trace "hit" as it is the absolute farthest distance gun can fire.
}
}
This traces from the center of the camera, using the cameras rotation as direction, and gets a point 65537 units forward. If trace is hit, it returns true. You can then use Hit.ImpactPoint as the vector in the world as to what is hit. The FHitResult also holds any Actors hit, such as players.