Yes, I 've already tried it - doesn’t work. Doesn’t work with wall-like objects to be specific. They burst all around, and I’m also noticing the pieces going back to the explosion origin, like bumerangs.
Here’s the method:
void AHatredBaseShotgun::Fire( AActor* shooter, AActor* target )
{
// place the damage origin between the shooter and the target, so that it appears
// the targets gets blown away by the force impulse ( a hack until they implement a linear force impulse )
FVector origin = target->GetActorLocation();
FVector impulseDir = origin - shooter->GetActorLocation();
impulseDir.SafeNormal2D();
// randomize the hit height a bit
{
FVector boundsOrigin, boxExtent;
target->GetActorBounds( true, boundsOrigin, boxExtent );
float randVal = ( float ) FMath::Rand() / ( float ) RAND_MAX - 0.5f;
origin.Z = boundsOrigin.Z + randVal * boxExtent.Z;
}
TArray< UPrimitiveComponent* > components;
target->GetComponents( components );
// Iterate over each and apply an impulse
const int16 count = components.Num();
for ( int16 i = 0; i < count; ++i )
{
UPrimitiveComponent* pokeComp = components*;
if ( pokeComp )
{
// If DestructibleDamage is non-zero, see if this is a destructible, and do damage if so.
if ( Damage > SMALL_NUMBER )
{
UDestructibleComponent* destructibleComp = Cast<UDestructibleComponent>( pokeComp );
if ( destructibleComp != NULL )
{
destructibleComp->ApplyDamage( Damage, origin, impulseDir, ImpulseStrength );
}
}
// Do impulse after
pokeComp->AddImpulseAtLocation( impulseDir* ImpulseStrength, origin );
}
}
}
The application of physical impulse afterwards serves the purpose of propelling ‘regular’ mesh components, as well as ( I was hoping that would work ) telling the Destructible components that it’s under influence of a force and should behave as such.
But let’s not forget - how do you actually query for the destructibles? Do you have them blueprinted, or do you place Destructibles on the level directly?
What method do you use to query for them?
Here’s what I tried:
Doesn’t work niether for standalone Destructibles nor the ones embedded in Blueprints
TArray<struct FHitResult> outHits;
{
const float Range = 10000.0f;
FVector shotDir = shooter->GetActorForwardVector();
FVector start = shooter->GetActorLocation(;
FVector end = start + shotDir * Range;
FCollisionQueryParams params;
FCollisionShape collisionShape;
collisionShape.SetSphere( 100.0f );
GetWorld()->SweepMulti( outHits, start, end, FQuat::Identity, ECC_Destructible, collisionShape, params );
// I tried several other collision layers, even though my destructibles all use this layer assignment - none of them worked
}
** Works only for the descructibles embedded in Blueprints**
TArray< AActor* > overlappingActors;
ShotgunFireConeMesh->GetOverlappingActors( overlappingActors ); // ShotgunFireConeMesh is an auxiliary, invisible static mesh component attached to my character
EDIT: just saw your addition about the iterators - I don’t want that. I want to be able to query a specific point on the level in search for destructibles. I want to use broadphase for that if possible.
The reason is that we plan on having large levels with lots of destructibles in them.
The other reason - we need to know how to manufacture them - arranged in prefabs, or is there posibility to place them ont he level directly.
Appreciate your help