LineTraceSingleByObjectType won't hit the object

I am trying to print out the object that the player is looking at using the LineTraceSingleByObjectType function. However, nothing is printing.

Here is the code:

// Called every frame
void ACPP_BaseCharacter::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	// Cursor Tracing
	auto temp = UGameplayStatics::GetPlayerCameraManager(this, 0);
	FCollisionObjectQueryParams ObjectParams;
	ObjectParams.AddObjectTypesToQuery(ECollisionChannel::ECC_WorldDynamic);
	FCollisionQueryParams Params;
	Params.AddIgnoredActor(this);
	
	GetWorld()->LineTraceSingleByObjectType(Looked, temp->GetCameraLocation(), temp->GetCameraLocation() + (GetActorForwardVector() * 500), ObjectParams, Params);
	
	if(Looked.GetActor())
	{
		// add snapping to object
		LookedActor = Looked.GetActor();
		GEngine->AddOnScreenDebugMessage(-1, 3.f, FColor::Yellow, LookedActor->GetActorLabel());
	}
}

Here is the collision presets I have:

maybe your camera is facing a different direction than GetActorForwardVector()

I realized the GetForwardActor needs to be from the camera not the player itself. This made it so that the Z vector was not moving at all! Thanks for the tip

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.