Hitbox struggle


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

APawn* OwnerPawn = Cast<APawn>(GetOwner());
if(!OwnerPawn) return;
AController* OwnerController = OwnerPawn->GetController();
if(!OwnerController) return;

FRotator Rotation;
FVector  Location;
OwnerController->GetPlayerViewPoint( Location, Rotation);

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

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

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

}

I try to shoot bullets out of a gun from the camera point of view. But for some reason the bullets collide with the character as can be seen in the image. I’m new to unreal and a bit confused why it doesn’t go through. I made a trace channel called bulled and ticked of different boxes that should make it pass through the character.

Try this:

FCollisionQueryParams QueryParams;
QueryParams.AddIgnoredActor(this);

bool bSuccess = GetWorld()->LineTraceSingleByChannel(Hit, Location, End, ECC_GameTraceChannel1, QueryParams);


I’m still experiencing the same problem. It’s like there is something it collides with.

This by any chance form Unreal Engine 5 C++ Developer: Learn C++ & Make Video Games?

Yes, I’m following a older one, as they made games I was more interested in.

Try same as above but use the owner QueryParams.AddIgnoredActor(OwnerPawn); since the trace is from the weapon actor passing this would just have the gun ignored.

That fixed the problem. Is it one of the changes in unreal 5 or just me? Thanks for the help

No. I’m sure the same issue persists in the lecture, it’s just that their camera is too far for it to happen.

1 Like

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