FHitResult* HitResult1 = new FHitResult();
FHitResult Hit1;
const float WeaponRange1 = 20000.0f;
//Attaching the line trace to the camera forward vector.
FVector CameraForward1 = FVector(FollowCamera->GetForwardVector());
FVector Rot = FollowCamera->GetComponentRotation().Vector();
const FVector ShotgunStartTrace = (FollowCamera->GetComponentLocation());
const FVector ShotgunEndTrace = (FollowCamera->GetForwardVector() + Rot * WeaponRange1);
FCollisionQueryParams ShotgunQueryParams = FCollisionQueryParams(SCENE_QUERY_STAT(WeaponTrace), false, this);
FCollisionQueryParams* ShotgunTraceParams = new FCollisionQueryParams();
//Here I am checking to see if the trace is active.
if (GetWorld()->LineTraceSingleByChannel(Hit1, ShotgunStartTrace, ShotgunEndTrace, ECC_Visibility, ShotgunQueryParams))
{
//FiringTheDebugLine
DrawDebugLine(GetWorld(), CameraForward1, Hit1.Location, FColor(255, 0, 0), false, -1, 0, 12.333);
}
I am firing from the third person character’s third person camera component and the debug line trace automatically hits the center of the map without regard for the end trace parameters that I had set is there an easy way to fix it. Any help would be appreciated thanks again. I am also using a skeletal mesh.
The Vector ShotgunEndTrace should probably be:
FVector ShotgunEndTrace = FollowCamera->GetComponentLocation() + (FollowCamera->GetForwardVector() * WeaponRange1);
Since you want to get a point that is WeaponRange1 away from the FollowCameraComponent in the forward direction of your camera.
Thank you! I really appreciate the help!