From 31f094d91d32754f03da36030f20f73394f18b64 Mon Sep 17 00:00:00 2001 From: Hades Fury Date: Thu, 25 Jul 2024 14:03:26 +0200 Subject: [PATCH 1/3] [DEV] Fix projectile overlap behaviour --- .../Private/GAS/Projectiles/GBFProjectile.cpp | 11 ++++++++++- .../Public/GAS/Projectiles/GBFProjectile.h | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Source/GameBaseFramework/Private/GAS/Projectiles/GBFProjectile.cpp b/Source/GameBaseFramework/Private/GAS/Projectiles/GBFProjectile.cpp index f129a1bc..2020535b 100644 --- a/Source/GameBaseFramework/Private/GAS/Projectiles/GBFProjectile.cpp +++ b/Source/GameBaseFramework/Private/GAS/Projectiles/GBFProjectile.cpp @@ -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 ) { @@ -225,6 +229,11 @@ void AGBFProjectile::OnSphereComponentBeginOverlap( UPrimitiveComponent * /* ove ProcessHit( hit_result ); } +void AGBFProjectile::OnSphereComponentEndOverlap( UPrimitiveComponent * /* overlapped_component */, AActor * /*other_actor*/, UPrimitiveComponent * other_component, int32 /* other_body_index */ ) +{ + IsInOverlap = 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..4e032940 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; From f2fb3e239fc2931156bd39858d9587fbb5a23903 Mon Sep 17 00:00:00 2001 From: Hades Fury Date: Thu, 25 Jul 2024 16:57:19 +0200 Subject: [PATCH 2/3] [DEV] Projectile overlap return a hitResult --- .../Private/GAS/Projectiles/GBFProjectile.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Source/GameBaseFramework/Private/GAS/Projectiles/GBFProjectile.cpp b/Source/GameBaseFramework/Private/GAS/Projectiles/GBFProjectile.cpp index 2020535b..0667d781 100644 --- a/Source/GameBaseFramework/Private/GAS/Projectiles/GBFProjectile.cpp +++ b/Source/GameBaseFramework/Private/GAS/Projectiles/GBFProjectile.cpp @@ -206,7 +206,7 @@ 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 ) { @@ -226,6 +226,11 @@ void AGBFProjectile::OnSphereComponentBeginOverlap( UPrimitiveComponent * /* ove other_component->SweepComponent( hit_result, GetActorLocation() - GetVelocity() * 10.f, GetActorLocation() + GetVelocity(), FQuat::Identity, SphereComponent->GetCollisionShape(), SphereComponent->bTraceComplexOnMove ); } + if ( ImpactDetectionType == EGBFProjectileImpactDetectionType::Overlap && hit_result.GetActor() == nullptr ) + { + hit_result = FHitResult( other_actor, other_component, FVector3d::Zero(), FVector3d::Zero() ); + } + ProcessHit( hit_result ); } From d8723f6e808e7c9c224c093866f3504b4da5a48b Mon Sep 17 00:00:00 2001 From: Hades Fury Date: Fri, 26 Jul 2024 09:30:17 +0200 Subject: [PATCH 3/3] [DEV] Fix according to PR reviews --- .../Private/GAS/Projectiles/GBFProjectile.cpp | 12 ++++++------ .../Public/GAS/Projectiles/GBFProjectile.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Source/GameBaseFramework/Private/GAS/Projectiles/GBFProjectile.cpp b/Source/GameBaseFramework/Private/GAS/Projectiles/GBFProjectile.cpp index 0667d781..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; } @@ -208,12 +208,12 @@ void AGBFProjectile::OnProjectileStop( const FHitResult & 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; @@ -226,9 +226,9 @@ void AGBFProjectile::OnSphereComponentBeginOverlap( UPrimitiveComponent * /* ove other_component->SweepComponent( hit_result, GetActorLocation() - GetVelocity() * 10.f, GetActorLocation() + GetVelocity(), FQuat::Identity, SphereComponent->GetCollisionShape(), SphereComponent->bTraceComplexOnMove ); } - if ( ImpactDetectionType == EGBFProjectileImpactDetectionType::Overlap && hit_result.GetActor() == nullptr ) + if ( hit_result.GetActor() == nullptr ) { - hit_result = FHitResult( other_actor, other_component, FVector3d::Zero(), FVector3d::Zero() ); + hit_result = FHitResult( other_actor, other_component, FVector::Zero(), FVector::Zero() ); } ProcessHit( hit_result ); @@ -236,7 +236,7 @@ void AGBFProjectile::OnSphereComponentBeginOverlap( UPrimitiveComponent * /* ove void AGBFProjectile::OnSphereComponentEndOverlap( UPrimitiveComponent * /* overlapped_component */, AActor * /*other_actor*/, UPrimitiveComponent * other_component, int32 /* other_body_index */ ) { - IsInOverlap = false; + bIsInOverlap = false; } void AGBFProjectile::ExecuteGameplayCue( const FGameplayTag gameplay_tag, const TFunctionRef< void( FGameplayCueParameters & gameplay_cue_parameters ) > & bp_function ) const diff --git a/Source/GameBaseFramework/Public/GAS/Projectiles/GBFProjectile.h b/Source/GameBaseFramework/Public/GAS/Projectiles/GBFProjectile.h index 4e032940..56881634 100644 --- a/Source/GameBaseFramework/Public/GAS/Projectiles/GBFProjectile.h +++ b/Source/GameBaseFramework/Public/GAS/Projectiles/GBFProjectile.h @@ -137,7 +137,7 @@ class GAMEBASEFRAMEWORK_API AGBFProjectile : public AActor UPROPERTY() UGBFAbilitySystemComponent * AbilitySystemComponent; - bool IsInOverlap; + bool bIsInOverlap; }; FORCEINLINE UGBFProjectileMovementComponent * AGBFProjectile::GetProjectileMovementComponent() const