Alternatives to LineTrace?

Hi,

I am trying to implement an item pickup system when using a fixed camera. I have it working fine with the code below, but I am doing a linetrace to detect if an item is in front of the player pawn and that means getting the player to look down to pickup items on the floor and up if its above the ground which is impractical with the camera.
What I would like to do is do a shapetrace (like a cone) or multiple linetraces to check multiple angles for a collectible item at multiple y values.
I was hoping someone might have some advice about a good way too achieve this?

/*
Performs ray-trace to find closest looked-at UsableActor.
*/
ASUsableActor* AOutbreakCharacter::GetUsableInView()
{
	FVector CamLoc;
	FRotator CamRot;

	if (Controller == nullptr)
		return nullptr;

	//Controller->GetPlayerViewPoint(CamLoc, CamRot);
	Controller->GetActorEyesViewPoint(CamLoc, CamRot);
	const FVector TraceStart = CamLoc;
	const FVector Direction = CamRot.Vector();
	const FVector TraceEnd = TraceStart + (Direction * MaxUseDistance);

	FCollisionQueryParams TraceParams(TEXT("TraceUsableActor"), true, this);
	TraceParams.bTraceAsyncScene = true;
	TraceParams.bReturnPhysicalMaterial = false;

	/* Not tracing complex uses the rough collision instead making tiny objects easier to select. */
	TraceParams.bTraceComplex = false;

	FHitResult Hit(ForceInit);

	GetWorld()->LineTraceSingleByChannel(Hit, TraceStart, TraceEnd, ECC_Visibility, TraceParams);
	GetWorld()->

	//GetWorld()->SweepSingleByChannel(Hit, TraceStart, TraceEnd, Orientation, ECC_Visibility, FCollisionShape::MakeBox(BoxHalfSize), TraceParams);
	//const FVector& BoxHalfExtent
	//GetWorld()->SweepSingleByChannel(Hit, TraceStart, TraceEnd, CamRot, ECC_Visibility, FCollisionShape::MakeBox(BoxHalfSize), TraceParams);

	DrawDebugLine(GetWorld(), TraceStart, TraceEnd, FColor::Red, false, 1.0f);

	//DrawDebugLine(GetWorld(), TraceStart, TraceEnd, FColor::Red, false, 1.0f);

	return Cast<ASUsableActor>(Hit.GetActor());
}

I normally do:

  1. check if player is close enough to pickup

  2. check if player’s camera’s forward vector is aimed more or less at pickup. (The angle between the camera’s forward vector and a vector from the camera to the pickup)

  3. do 1 line trace to make sure the object is not on the other side of a wall or other obstacle

As many others have suggested perform a Multi-Sphere Trace which will get all items within a radius of the sphere. This is pretty fast performance wise. If you have multiple items that could theoretically be within the bounds and you want to only pickup the closest one you are facing you and first determine if your character is looking in the same direction as the item. There are a few methods to do this using line traces, sweeps, or even the Dot Product to determine which item the character is “most” looking at.

Can’t you just add a collision sphere and check for an overlap with your player mesh?. If not then maybe a shape trace would do, here is the relevant documentation: ShapeTrace

Thanks, I am trying to do a shape trace with a box, but I am having a bit of trouble creating the actual shape. I was hoping to create a box roughly the same size as the player pawn so it would detect items on the floor and eye level etc. so I thought I would just need to give it a vector with a big Y value. Also, I thought a capsule might be better, but it seems to stretch behind thee player actor when I only really want it in front. Is there a way to render the shape like you can with debug line?

Thanks for the advice, I am using the single shape trace sweep method, but I am having some trouble getting the size of the shape right and its a tedious process doing it trial and error. Do you know if there is a way to render the trace shape like you can with a debug line?

This is how I am currently calling it:

FVector BoxHalfSize(30, 30, 120);

	//GetWorld()->SweepSingleByChannel(Hit, TraceStart, TraceEnd, TraceRot, ECC_Visibility, FCollisionShape::MakeCapsule(100.0f, 80.0f), TraceParams);
	GetWorld()->SweepSingleByChannel(Hit, TraceStart, TraceEnd, TraceRot, ECC_Visibility, FCollisionShape::MakeBox(BoxHalfSize), TraceParams);

Try this:
DrawDebugBox(GetWorld(), TraceStart, UseBoxHalfSize, FColor::Red, false, 1.0f, 0);