Add Enemy AI Behaviour Task for Attacking Player
This commit is contained in:
parent
174becfdf1
commit
b1531a5acf
@ -0,0 +1,27 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "BTTask_AttackPlayer.h"
|
||||
|
||||
#include "AI_EnemyController.h"
|
||||
#include "BehaviorTree/BlackboardComponent.h"
|
||||
|
||||
UBTTask_AttackPlayer::UBTTask_AttackPlayer(FObjectInitializer const& ObjectInitializer)
|
||||
{
|
||||
}
|
||||
|
||||
EBTNodeResult::Type UBTTask_AttackPlayer::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
|
||||
{
|
||||
if (const AAI_EnemyController* const AIController = Cast<AAI_EnemyController>(OwnerComp.GetAIOwner()))
|
||||
{
|
||||
if (const UBlackboardComponent* const Blackboard = OwnerComp.GetBlackboardComponent())
|
||||
{
|
||||
FVector const Origin = AIController->GetPawn()->GetActorLocation();
|
||||
FVector const PlayerLocation = Blackboard->GetValueAsVector("TargetLocation");
|
||||
DrawDebugLine(GetWorld(), Origin, PlayerLocation, FColor::Green, false, 1.f, 0, 1.f);
|
||||
FinishLatentTask(OwnerComp, EBTNodeResult::Succeeded);
|
||||
return EBTNodeResult::Succeeded;
|
||||
}
|
||||
}
|
||||
return EBTNodeResult::Failed;
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "BehaviorTree/Tasks/BTTask_BlackboardBase.h"
|
||||
#include "BTTask_AttackPlayer.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class ENDLESSVENDETTA_API UBTTask_AttackPlayer : public UBTTask_BlackboardBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
public:
|
||||
explicit UBTTask_AttackPlayer(FObjectInitializer const& ObjectInitializer);
|
||||
virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) override;
|
||||
};
|
Loading…
Reference in New Issue
Block a user