Update Enemy AI to Shoot w/ VFX, SFX & Animation

This commit is contained in:
Philip W 2024-02-16 19:04:14 +00:00
parent e4ff17cf4a
commit 0e6c2d5d05
6 changed files with 25 additions and 24 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -42,7 +42,12 @@ public:
UFUNCTION(BlueprintNativeEvent)
void SetFiring(bool IsFiring);
virtual void SetFiring_Implementation(bool IsFiring);
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FFireWeapon);
UPROPERTY(BlueprintAssignable, Category = "AI")
FFireWeapon FireWeapon;
private:
FDelegateHandle AlertLevelDelegateHandle;
FDelegateHandle HuntPlayerDelegateHandle;

View File

@ -23,23 +23,22 @@ EBTNodeResult::Type UBTTask_AttackPlayer::ExecuteTask(UBehaviorTreeComponent& Ow
FVector const Origin = AIController->GetPawn()->GetActorLocation();
FVector const Start = Origin + FVector(0.f, 0.f, 30.f);
FVector const PlayerLocation = Blackboard->GetValueAsVector("TargetLocation");
DrawDebugLine(GetWorld(), Start, PlayerLocation, FColor::Black, false, 1.f, 0, 1.f);
FCollisionQueryParams QueryParams;
QueryParams.AddIgnoredActor(AIController->GetPawn());
if (FHitResult HitResult; GetWorld()->LineTraceSingleByChannel(HitResult, Start, PlayerLocation, ECC_Pawn, QueryParams))
{
if (IsValid(HitResult.GetActor()))
{
if (HitResult.GetActor()->ActorHasTag("Player"))
{
Cast<AEndlessVendettaCharacter>(HitResult.GetActor())->TakeDamage(5.0f, FPointDamageEvent(), AIController->GetInstigatorController(), AIController->GetPawn());
}
}
}
if (AEnemyCharacter* const EnemyCharacter = Cast<AEnemyCharacter>(AIController->GetPawn()))
{
EnemyCharacter->FireWeapon.Broadcast();
EnemyCharacter->SetFiring(true);
FCollisionQueryParams QueryParams;
QueryParams.AddIgnoredActor(AIController->GetPawn());
if (FHitResult HitResult; GetWorld()->LineTraceSingleByChannel(HitResult, Start, PlayerLocation, ECC_Pawn, QueryParams))
{
if (IsValid(HitResult.GetActor()))
{
if (HitResult.GetActor()->ActorHasTag("Player"))
{
Cast<AEndlessVendettaCharacter>(HitResult.GetActor())->TakeDamage(5.0f, FPointDamageEvent(), AIController->GetInstigatorController(), AIController->GetPawn());
}
}
}
FinishLatentTask(OwnerComp, EBTNodeResult::Succeeded);
return EBTNodeResult::Succeeded;