That depends how you define collision, I just check if the trace hit something, if it did not just continue to next loop. if it did, rotate the direction vector and update location vector for next loop.
They do lol… they are all bunched up inside the box.
For example, this is the function that updates the structs on tick:
// Called every frame
void AProjectileTraceManager::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
AddActorWorldRotation(FRotator(0.f, 100.f * DeltaTime, 0.f));
TraceManager(DeltaTime);
}
void AProjectileTraceManager::TraceManager(float DeltaTime)
{
for (FProjectileStructBase& Projectile : ProjectileStructArray)
{
FHitResult HitResult;
FCollisionQueryParams QueryParams;
float TraceDistance = ProjectileSpeed * DeltaTime;
GetWorld()->LineTraceSingleByChannel(
HitResult,
Projectile.WorldLocation,
TraceDistance * Projectile.Direction + Projectile.WorldLocation,
ECollisionChannel::ECC_Visibility,
QueryParams,
FCollisionResponseParams::DefaultResponseParam
);
DrawDebugLine(
GetWorld(),
Projectile.WorldLocation,
HitResult.TraceEnd,
FColor::Red,
false, -1.f, 0, 2.f
);
// If no hit, jump to next loop
if (!HitResult.bBlockingHit)
{
Projectile.WorldLocation = HitResult.TraceEnd;
continue; // Anything after this will never run for this loop
UE_LOG(LogTemp, Warning, TEXT("This will never run."));
}
// Rotate direction vector from hit normal for next loop.
float dot = HitResult.ImpactNormal | (Projectile.Direction * (-1.f));
FVector BounceDirection = ((HitResult.ImpactNormal * dot * 2.f) + Projectile.Direction);
Projectile.Direction = BounceDirection;
// Update location of struct for next loop
float DistanceToBlockHit = FVector::Distance(Projectile.WorldLocation, HitResult.ImpactPoint);
float DistanceAfterBlock = TraceDistance - DistanceToBlockHit;
Projectile.WorldLocation = HitResult.ImpactPoint + Projectile.Direction * DistanceAfterBlock;
}
}
idk how will this perform in blueprint… also don’t remember what is the equivalent of continue; in blueprint.
Since this traces from point A to B and next loop from B to C, it should never go through anything unless that moves against the direction of the projectile, but I think you can work around that by playing with the tick groups.