Create AI `TaskFireWeapon` node

This commit is contained in:
Louis Hobbs 2023-03-13 22:23:42 +00:00
parent bf742b0224
commit e77b6cce35
2 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,20 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "TaskFireWeapon.h"
#include "EnemyAIController.h"
EBTNodeResult::Type UTaskFireWeapon::ExecuteTask(UBehaviorTreeComponent& owner, uint8* memory)
{
auto enemyController = Cast<AEnemyAIController>(owner.GetAIOwner());
auto enemyPawn = Cast<AEnemyCharacter>(enemyController->GetPawn());
auto blackboardComponent = owner.GetBlackboardComponent();
auto playerCharacter = Cast<APlayerCharacter>(blackboardComponent->GetValueAsObject(TargetActor.SelectedKeyName));
if (enemyPawn && playerCharacter)
{
enemyPawn->OnFire();
return EBTNodeResult::Succeeded;
}
return EBTNodeResult::Failed;
}

View File

@ -0,0 +1,23 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "BehaviorTree/BTTaskNode.h"
#include "TaskFireWeapon.generated.h"
/**
*
*/
UCLASS()
class NAKATOMI_API UTaskFireWeapon : public UBTTaskNode
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, Category = "Options", Meta = (AllowPrivateAccess = "true", DisplayName = "Target Actor Key"))
FBlackboardKeySelector TargetActor;
virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent& owner, uint8* memory) override;
};