void ABomb::ApplyExplosionDamage() { for ( TActorIterator<ANetGameCPPCharacter> aItr(GetWorld()); aItr; ++aItr ) { if ( GetDistanceTo(*aItr) <= ExplosionRadius) UGameplayStatics::ApplyDamage(*aItr, ExplosionDamage, GetInstigatorController(), this, UDamageType::StaticClass()); } OnExplosion(); SetLifeSpan(2.0f); }
void AProjectile::Explode() { BP_Explode(); const FVector Loc = GetActorLocation(); for (TActorIterator<AActor> aItr(GetWorld()); aItr; ++aItr) { const float distance = GetDistanceTo(*aItr); if (distance<AffectArea && aItr && aItr->GetRootComponent() && aItr->GetRootComponent()->Mobility == EComponentMobility::Movable) { FVector dir = aItr->GetActorLocation() - Loc; dir.Normalize(); FRichCurve* RadialDamageCurveData = RadialDamageCurve.GetRichCurve(); FRichCurve* RadialImpulseCurveData = RadialImpulseCurve.GetRichCurve(); ABaseCharacter* theChar = Cast<ABaseCharacter>(*aItr); //If Player apply damage if (theChar && RadialDamageCurveData) { //printr("Apply Damage"); UGameplayStatics::ApplyDamage(theChar, RadialDamageCurveData->Eval(distance), NULL, this, ExplosionDamageType); } if (RadialImpulseCurveData && aItr->GetRootComponent()->IsSimulatingPhysics() && Cast<UPrimitiveComponent>(aItr->GetRootComponent())) { Cast<UPrimitiveComponent>(aItr->GetRootComponent())->AddImpulse(dir*RadialImpulseCurveData->Eval(distance)); } } } Destroy(); }