diff --git a/Source/Nakatomi/TaskGetLocationNearLocation.cpp b/Source/Nakatomi/TaskGetLocationNearLocation.cpp new file mode 100644 index 0000000..6febcd0 --- /dev/null +++ b/Source/Nakatomi/TaskGetLocationNearLocation.cpp @@ -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 + +EBTNodeResult::Type UTaskGetLocationNearLocation::ExecuteTask(UBehaviorTreeComponent& owner, uint8* memory) +{ + auto enemyController = Cast(owner.GetAIOwner()); + auto enemyPawn = Cast(enemyController->GetPawn()); + auto blackboardComponent = owner.GetBlackboardComponent(); + auto navigationSystem = FNavigationSystem::GetCurrent(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; +} diff --git a/Source/Nakatomi/TaskGetLocationNearLocation.h b/Source/Nakatomi/TaskGetLocationNearLocation.h new file mode 100644 index 0000000..a0b8e95 --- /dev/null +++ b/Source/Nakatomi/TaskGetLocationNearLocation.h @@ -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; +};