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

@ -43,6 +43,11 @@ public:
void SetFiring(bool IsFiring); void SetFiring(bool IsFiring);
virtual void SetFiring_Implementation(bool IsFiring); virtual void SetFiring_Implementation(bool IsFiring);
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FFireWeapon);
UPROPERTY(BlueprintAssignable, Category = "AI")
FFireWeapon FireWeapon;
private: private:
FDelegateHandle AlertLevelDelegateHandle; FDelegateHandle AlertLevelDelegateHandle;
FDelegateHandle HuntPlayerDelegateHandle; FDelegateHandle HuntPlayerDelegateHandle;

View File

@ -23,8 +23,10 @@ EBTNodeResult::Type UBTTask_AttackPlayer::ExecuteTask(UBehaviorTreeComponent& Ow
FVector const Origin = AIController->GetPawn()->GetActorLocation(); FVector const Origin = AIController->GetPawn()->GetActorLocation();
FVector const Start = Origin + FVector(0.f, 0.f, 30.f); FVector const Start = Origin + FVector(0.f, 0.f, 30.f);
FVector const PlayerLocation = Blackboard->GetValueAsVector("TargetLocation"); FVector const PlayerLocation = Blackboard->GetValueAsVector("TargetLocation");
DrawDebugLine(GetWorld(), Start, PlayerLocation, FColor::Black, false, 1.f, 0, 1.f); if (AEnemyCharacter* const EnemyCharacter = Cast<AEnemyCharacter>(AIController->GetPawn()))
{
EnemyCharacter->FireWeapon.Broadcast();
EnemyCharacter->SetFiring(true);
FCollisionQueryParams QueryParams; FCollisionQueryParams QueryParams;
QueryParams.AddIgnoredActor(AIController->GetPawn()); QueryParams.AddIgnoredActor(AIController->GetPawn());
if (FHitResult HitResult; GetWorld()->LineTraceSingleByChannel(HitResult, Start, PlayerLocation, ECC_Pawn, QueryParams)) if (FHitResult HitResult; GetWorld()->LineTraceSingleByChannel(HitResult, Start, PlayerLocation, ECC_Pawn, QueryParams))
@ -37,9 +39,6 @@ EBTNodeResult::Type UBTTask_AttackPlayer::ExecuteTask(UBehaviorTreeComponent& Ow
} }
} }
} }
if (AEnemyCharacter* const EnemyCharacter = Cast<AEnemyCharacter>(AIController->GetPawn()))
{
EnemyCharacter->SetFiring(true);
FinishLatentTask(OwnerComp, EBTNodeResult::Succeeded); FinishLatentTask(OwnerComp, EBTNodeResult::Succeeded);
return EBTNodeResult::Succeeded; return EBTNodeResult::Succeeded;