Strange problem when line tracing

I’ve followed Sam’s instructions exactly in the LineTracingByChannel lecture, and at the end of the lecture I’ve gotten this strange problem:


This is the PullTrigger method’s code:

void AGun::PullTrigger()
{
	UGameplayStatics::SpawnEmitterAttached(MuzzleFlash, Mesh, TEXT("MuzzleFlashSocket"));

	APawn* OwnerPawn = Cast<APawn>(GetOwner());
	if (OwnerPawn == nullptr) return;

	AController* OwnerController = OwnerPawn->GetController();
	if (OwnerController == nullptr) return;

	FVector Location;
	FRotator Rotation;

	OwnerController->GetPlayerViewPoint(Location, Rotation);

	FVector End = Location + Rotation.Vector() * MaxRange;

	//TODO Linetrace

	FHitResult Hit;
	bool bSuccess = GetWorld()->LineTraceSingleByChannel(Hit, Location, End, ECollisionChannel::ECC_GameTraceChannel1);

	if (bSuccess)
	{
		DrawDebugPoint(GetWorld(), Hit.Location, 20, FColor::Red, true);
	}
}

MaxRange is set to 1000 too, so I don’t know why it’s not working
I really need someone to help solve this problem so I can continue the section, any help given would be appreciated.

I’ve figured out the problem, turns out there is collision with Pawn, but if I set it to ignore I can’t hit AI so I’ll try to make the camera not hit the character. :sweat_smile:

Nevermind again, aicontrollers don’t inherit from pawn which means I can set collision to ignore for pawns

Just ignore the pawn

FCollisionQueryParams Params(NAME_None, true, OwnerPawn);
bool bSuccess = GetWorld()->LineTraceSingleByChannel(Hit, Location, End, ECollisionChannel::ECC_GameTraceChannel1, Params);
4 Likes

Yeah, I did that, but thanks

This is coming up in a later lecture actually.

1 Like

Yeah I was sure you wouldn’t leave that behind.

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

Privacy & Terms