Create TaskIsWithinRange
This commit is contained in:
parent
bc0138251a
commit
969ecbebc8
|
@ -0,0 +1,34 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "TaskIsWithinRange.h"
|
||||
#include "EnemyAIController.h"
|
||||
#include <NavigationSystem.h>
|
||||
#include <BehaviorTree/BlackboardComponent.h>
|
||||
|
||||
EBTNodeResult::Type UTaskIsWithinRange::ExecuteTask(UBehaviorTreeComponent& owner, uint8* memory)
|
||||
{
|
||||
auto BlackboardComponent = owner.GetBlackboardComponent();
|
||||
|
||||
if (!BlackboardComponent)
|
||||
{
|
||||
return EBTNodeResult::Failed;
|
||||
}
|
||||
|
||||
auto NavigationSystem = FNavigationSystem::GetCurrent<UNavigationSystemV1>(GetWorld());
|
||||
FVector SourceLocation = BlackboardComponent->GetValueAsVector(SourceLocationKey.SelectedKeyName);
|
||||
ANakatomiCharacter* selfActor = Cast<ANakatomiCharacter>(
|
||||
BlackboardComponent->GetValueAsObject(SelfActorKey.SelectedKeyName));
|
||||
|
||||
if (NavigationSystem && SourceLocation != FVector::ZeroVector)
|
||||
{
|
||||
double Distance = -1.0;
|
||||
FNavLocation NavLocation;
|
||||
|
||||
NavigationSystem->GetPathLength(SourceLocation, selfActor->GetTransform().GetLocation(), Distance);
|
||||
|
||||
return Distance <= MaximumDistance ? EBTNodeResult::Succeeded : EBTNodeResult::Failed;
|
||||
}
|
||||
|
||||
return EBTNodeResult::Failed;
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "BehaviorTree/BTTaskNode.h"
|
||||
#include "TaskIsWithinRange.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class NAKATOMI_API UTaskIsWithinRange : public UBTTaskNode
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
UPROPERTY(EditAnywhere, Category = "Options",
|
||||
Meta = (AllowPrivateAccess = "true", DisplayName = "Source Location Key"))
|
||||
FBlackboardKeySelector SourceLocationKey;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category = "Options",
|
||||
Meta = (AllowPrivateAccess = "true", DisplayName = "Self Actor Key"))
|
||||
FBlackboardKeySelector SelfActorKey;
|
||||
|
||||
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