Skip to content

Fix projectile overlap behaviour #282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions Source/GameBaseFramework/Private/GAS/Projectiles/GBFProjectile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ AGBFProjectile::AGBFProjectile()

ImpactDetectionType = EGBFProjectileImpactDetectionType::Hit;
bIgnoreImpactWithInstigator = true;
IsInOverlap = false;
bIsInOverlap = false;
ApplyGameplayEffectsPhase = EGBFProjectileApplyGameplayEffectsPhase::OnHit;
bUseHitResultAsLocationForGameplayEffects = true;
}
Expand All @@ -49,6 +49,7 @@ void AGBFProjectile::PostInitializeComponents()
case EGBFProjectileImpactDetectionType::Overlap:
{
SphereComponent->OnComponentBeginOverlap.AddDynamic( this, &AGBFProjectile::OnSphereComponentBeginOverlap );
SphereComponent->OnComponentEndOverlap.AddDynamic( this, &AGBFProjectile::OnSphereComponentEndOverlap );
}
break;
default:
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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;

Expand All @@ -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() )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -134,7 +137,7 @@ class GAMEBASEFRAMEWORK_API AGBFProjectile : public AActor
UPROPERTY()
UGBFAbilitySystemComponent * AbilitySystemComponent;

bool IsInOverlap;
bool bIsInOverlap;
};

FORCEINLINE UGBFProjectileMovementComponent * AGBFProjectile::GetProjectileMovementComponent() const
Expand Down
Loading