Not sure if this is a bug, my own code, or me just not understanding how box traces work, but when I try to do a box trace (I’m trying to do a very tall one) it’s not registering any hits when the Z value is greater than around 95 units. Mind taking a look?
// Calculating the start and end points of our line trace, and applying randomised variation
TraceStart = PlayerCharacter->GetCapsuleComponent()->GetComponentLocation();
TraceStartRotation = PlayerCharacter->GetCapsuleComponent()->GetComponentRotation();
TraceStartRotation.Pitch += FMath::FRandRange(-WeaponData.ShotVariation, WeaponData.ShotVariation);
TraceStartRotation.Yaw += FMath::FRandRange(-WeaponData.ShotVariation, WeaponData.ShotVariation);
TraceDirection = TraceStartRotation.Vector();
TraceEnd = TraceStart + (TraceDirection * WeaponData.ShotDistanceMultiplier);
FVector EndPoint = TraceEnd;
/** collision parameters for spawning the line trace */
FCollisionQueryParams QueryParams;
//Sets the default values for our trace query
QueryParams.AddIgnoredActor(this);
QueryParams.AddIgnoredActor(PlayerCharacter);
QueryParams.bTraceComplex = true;
QueryParams.bReturnPhysicalMaterial = true;
// No collision when Z value is above ~95??????????????
FCollisionShape Shape = FCollisionShape::MakeBox(FVector(100, 100, 90));
// Drawing a line trace based on the parameters calculated previously
//if (GetWorld()->LineTraceSingleByChannel(Hit, TraceStart, TraceEnd, ECC_GameTraceChannel1, QueryParams))
if (GetWorld()->SweepSingleByChannel(Hit, TraceStart, TraceEnd, PlayerCharacter->GetActorQuat(), ECC_GameTraceChannel1, Shape, QueryParams))
{
// Drawing debug line trace
if (bShowDebug)
{
// Debug line from muzzle to hit location
DrawDebugBox(
GetWorld(), TraceStart, Shape.GetExtent(), PlayerCharacter->GetActorQuat(),
FColor::Red, false, 0.3f, 0.0f, 0.5f);
DrawDebugBox(
GetWorld(), Hit.Location, Shape.GetExtent(), PlayerCharacter->GetActorQuat(),
FColor::Green, false, 0.3f, 0.0f, 0.5f);
}
FinalDamage = (WeaponData.BaseDamage + DamageModifier);
AActor* HitActor = Hit.GetActor();
// Applying the previously set damage to the hit actor
UGameplayStatics::ApplyPointDamage(HitActor, FinalDamage, TraceDirection, Hit,
GetOwner()->GetInstigatorController(), this, DamageType);
EndPoint = Hit.Location;
// Passing hit delegate to InventoryComponent
ATP_ThirdPersonCharacter* MyCharacter = Cast<ATP_ThirdPersonCharacter>(GetOwner());
if (MyCharacter)
{
UInventoryComponent* PlayerInventoryComp = MyCharacter->FindComponentByClass<UInventoryComponent>();
if (IsValid(PlayerInventoryComp))
{
PlayerInventoryComp->EventHitActor.Broadcast(Hit);
}
}
}
else
{
// Drawing debug line trace
if (bShowDebug)
{
DrawDebugBox(
GetWorld(), TraceStart, Shape.GetExtent(), PlayerCharacter->GetActorQuat(),
FColor::Red, false, 0.3f, 0.0f, 2.0f);
}
}
const FRotator ParticleRotation = (EndPoint - TraceStart).Rotation();
UNiagaraFunctionLibrary::SpawnSystemAtLocation(GetWorld(), WeaponData.TraceEffect, TraceStart, ParticleRotation);
if (Hit.GetActor() && Hit.GetActor()->IsA<APawn>())
{
UNiagaraFunctionLibrary::SpawnSystemAtLocation(GetWorld(), WeaponData.EnemyHitEffect, Hit.ImpactPoint, Hit.ImpactNormal.Rotation());
}
else
{
UNiagaraFunctionLibrary::SpawnSystemAtLocation(GetWorld(), WeaponData.DefaultHitEffect, Hit.ImpactPoint, Hit.ImpactNormal.Rotation());
}
(there is some redundant code in here from when it was a line trace I need to clean up)