Add TaskGetLocationNearLocation AI Task
This commit is contained in:
parent
5e65a6ff35
commit
b10311e3d1
|
@ -0,0 +1,27 @@
|
||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "TaskGetLocationNearLocation.h"
|
||||||
|
#include "EnemyAIController.h"
|
||||||
|
#include "EnemyCharacter.h"
|
||||||
|
#include <NavigationSystem.h>
|
||||||
|
|
||||||
|
EBTNodeResult::Type UTaskGetLocationNearLocation::ExecuteTask(UBehaviorTreeComponent& owner, uint8* memory)
|
||||||
|
{
|
||||||
|
auto enemyController = Cast<AEnemyAIController>(owner.GetAIOwner());
|
||||||
|
auto enemyPawn = Cast<AEnemyCharacter>(enemyController->GetPawn());
|
||||||
|
auto blackboardComponent = owner.GetBlackboardComponent();
|
||||||
|
auto navigationSystem = FNavigationSystem::GetCurrent<UNavigationSystemV1>(GetWorld());
|
||||||
|
FVector sourceLocation = blackboardComponent->GetValueAsVector(SourceLocationKey.SelectedKeyName);
|
||||||
|
|
||||||
|
if (blackboardComponent && navigationSystem && sourceLocation != FVector::ZeroVector)
|
||||||
|
{
|
||||||
|
FNavLocation navLocation;
|
||||||
|
navigationSystem->GetRandomReachablePointInRadius(sourceLocation, MaximumDistance, navLocation);
|
||||||
|
|
||||||
|
blackboardComponent->SetValueAsVector(TargetLocationKey.SelectedKeyName, navLocation.Location);
|
||||||
|
return EBTNodeResult::Succeeded;
|
||||||
|
}
|
||||||
|
|
||||||
|
return EBTNodeResult::Failed;
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "BehaviorTree/BTTaskNode.h"
|
||||||
|
#include "TaskGetLocationNearLocation.generated.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
UCLASS()
|
||||||
|
class NAKATOMI_API UTaskGetLocationNearLocation : public UBTTaskNode
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
UPROPERTY(EditAnywhere, Category = "Options",
|
||||||
|
Meta = (AllowPrivateAccess = "true", DisplayName = "Target Location Key"))
|
||||||
|
FBlackboardKeySelector TargetLocationKey;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, Category = "Options",
|
||||||
|
Meta = (AllowPrivateAccess = "true", DisplayName = "Source Location Key"))
|
||||||
|
FBlackboardKeySelector SourceLocationKey;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, Category = "Options",
|
||||||
|
Meta = (AllowPrivateAccess = "true", DisplayName = "Maximum Distance"))
|
||||||
|
float MaximumDistance = 500.0f;
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent& owner, uint8* memory) override;
|
||||||
|
};
|
Loading…
Reference in New Issue