diff --git a/Source/GameBaseFramework/Private/GAS/Projectiles/GBFProjectile.cpp b/Source/GameBaseFramework/Private/GAS/Projectiles/GBFProjectile.cpp index f129a1bc..9cc6c8e3 100644 --- a/Source/GameBaseFramework/Private/GAS/Projectiles/GBFProjectile.cpp +++ b/Source/GameBaseFramework/Private/GAS/Projectiles/GBFProjectile.cpp @@ -30,7 +30,7 @@ AGBFProjectile::AGBFProjectile() ImpactDetectionType = EGBFProjectileImpactDetectionType::Hit; bIgnoreImpactWithInstigator = true; - IsInOverlap = false; + bIsInOverlap = false; ApplyGameplayEffectsPhase = EGBFProjectileApplyGameplayEffectsPhase::OnHit; bUseHitResultAsLocationForGameplayEffects = true; } @@ -49,6 +49,7 @@ void AGBFProjectile::PostInitializeComponents() case EGBFProjectileImpactDetectionType::Overlap: { SphereComponent->OnComponentBeginOverlap.AddDynamic( this, &AGBFProjectile::OnSphereComponentBeginOverlap ); + SphereComponent->OnComponentEndOverlap.AddDynamic( this, &AGBFProjectile::OnSphereComponentEndOverlap ); } break; default: @@ -148,7 +149,10 @@ void AGBFProjectile::ProcessHit( const FHitResult & hit_result ) return; } - SetActorLocation( hit_result.ImpactPoint + hit_result.ImpactNormal ); + if ( ImpactDetectionType == EGBFProjectileImpactDetectionType::Hit ) + { + SetActorLocation( hit_result.ImpactPoint + hit_result.ImpactNormal ); + } if ( ImpactSpawnActorClass != nullptr ) { @@ -202,14 +206,14 @@ void AGBFProjectile::OnProjectileStop( const FHitResult & hit_result ) ProcessHit( hit_result ); } -void AGBFProjectile::OnSphereComponentBeginOverlap( UPrimitiveComponent * /* overlapped_component */, AActor * /*other_actor*/, UPrimitiveComponent * other_component, int32 /* other_body_index */, bool from_sweep, const FHitResult & sweep_hit_result ) +void AGBFProjectile::OnSphereComponentBeginOverlap( UPrimitiveComponent * /* overlapped_component */, AActor * other_actor, UPrimitiveComponent * other_component, int32 /* other_body_index */, bool from_sweep, const FHitResult & sweep_hit_result ) { - if ( IsInOverlap ) + if ( bIsInOverlap ) { return; } - TGuardValue< bool > overlap_guard( IsInOverlap, true ); // Sets IsInOverlap to true, and restores it in dtor. + TGuardValue< bool > overlap_guard( bIsInOverlap, true ); // Sets IsInOverlap to true, and restores it in dtor. FHitResult hit_result; @@ -222,9 +226,19 @@ void AGBFProjectile::OnSphereComponentBeginOverlap( UPrimitiveComponent * /* ove other_component->SweepComponent( hit_result, GetActorLocation() - GetVelocity() * 10.f, GetActorLocation() + GetVelocity(), FQuat::Identity, SphereComponent->GetCollisionShape(), SphereComponent->bTraceComplexOnMove ); } + if ( hit_result.GetActor() == nullptr ) + { + hit_result = FHitResult( other_actor, other_component, FVector::Zero(), FVector::Zero() ); + } + ProcessHit( hit_result ); } +void AGBFProjectile::OnSphereComponentEndOverlap( UPrimitiveComponent * /* overlapped_component */, AActor * /*other_actor*/, UPrimitiveComponent * other_component, int32 /* other_body_index */ ) +{ + bIsInOverlap = false; +} + void AGBFProjectile::ExecuteGameplayCue( const FGameplayTag gameplay_tag, const TFunctionRef< void( FGameplayCueParameters & gameplay_cue_parameters ) > & bp_function ) const { if ( IsValid( AbilitySystemComponent ) && gameplay_tag.IsValid() ) diff --git a/Source/GameBaseFramework/Public/GAS/Projectiles/GBFProjectile.h b/Source/GameBaseFramework/Public/GAS/Projectiles/GBFProjectile.h index 9b5f0ae8..56881634 100644 --- a/Source/GameBaseFramework/Public/GAS/Projectiles/GBFProjectile.h +++ b/Source/GameBaseFramework/Public/GAS/Projectiles/GBFProjectile.h @@ -103,6 +103,9 @@ class GAMEBASEFRAMEWORK_API AGBFProjectile : public AActor UFUNCTION() void OnSphereComponentBeginOverlap( UPrimitiveComponent * overlapped_component, AActor * other_actor, UPrimitiveComponent * other_component, int32 other_body_index, bool from_sweep, const FHitResult & sweep_hit_result ); + UFUNCTION() + void OnSphereComponentEndOverlap( UPrimitiveComponent * overlapped_component, AActor * other_actor, UPrimitiveComponent * other_component, int32 other_body_index ); + UPROPERTY( BlueprintReadOnly, VisibleAnywhere, Category = "Projectile", meta = ( AllowPrivateAccess = true ) ) USphereComponent * SphereComponent; @@ -134,7 +137,7 @@ class GAMEBASEFRAMEWORK_API AGBFProjectile : public AActor UPROPERTY() UGBFAbilitySystemComponent * AbilitySystemComponent; - bool IsInOverlap; + bool bIsInOverlap; }; FORCEINLINE UGBFProjectileMovementComponent * AGBFProjectile::GetProjectileMovementComponent() const