diff --git a/Content/CombatSystem/Blueprints/AI/GruntlingEnemy/BT_GruntlingEnemy.uasset b/Content/CombatSystem/Blueprints/AI/GruntlingEnemy/BT_GruntlingEnemy.uasset index bcdcbd16..e5bea75c 100644 Binary files a/Content/CombatSystem/Blueprints/AI/GruntlingEnemy/BT_GruntlingEnemy.uasset and b/Content/CombatSystem/Blueprints/AI/GruntlingEnemy/BT_GruntlingEnemy.uasset differ diff --git a/Source/D1/AI/BehaviorTreeNodes/T_TryGetRandomPatrolPoint.cpp b/Source/D1/AI/BehaviorTreeNodes/T_TryGetRandomPatrolPoint.cpp new file mode 100644 index 00000000..afc77dda --- /dev/null +++ b/Source/D1/AI/BehaviorTreeNodes/T_TryGetRandomPatrolPoint.cpp @@ -0,0 +1,44 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "AI/BehaviorTreeNodes/T_TryGetRandomPatrolPoint.h" + +#include "AIController.h" +#include "NavigationData.h" +#include "NavigationSystem.h" +#include "BehaviorTree/BlackboardComponent.h" + +UT_TryGetRandomPatrolPoint::UT_TryGetRandomPatrolPoint() +{ + Radius = 500.f; + QueryExtent = {300.f, 300.f, 300.f}; +} + +EBTNodeResult::Type UT_TryGetRandomPatrolPoint::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) +{ + EBTNodeResult::Type result = Super::ExecuteTask(OwnerComp, NodeMemory); + if(result == EBTNodeResult::Failed) + return EBTNodeResult::Failed; + + APawn* ControllingPawn = OwnerComp.GetAIOwner()->GetPawn(); + if(ControllingPawn == nullptr) + return EBTNodeResult::Failed; + + UNavigationSystemV1* NavSystem = UNavigationSystemV1::GetNavigationSystem(ControllingPawn->GetWorld()); + if(NavSystem == nullptr) + return EBTNodeResult::Failed; + + FVector CurLocation = ControllingPawn->GetActorLocation(); + FNavLocation RandomLocation, ProjectLocation; + if(NavSystem->GetRandomReachablePointInRadius(CurLocation, Radius, RandomLocation)) + { + if(NavSystem->ProjectPointToNavigation(RandomLocation.Location, ProjectLocation, QueryExtent)) + OwnerComp.GetBlackboardComponent()->SetValueAsVector(BlackboardKey_TargetLocation.SelectedKeyName, ProjectLocation.Location); + else + return EBTNodeResult::Failed; + } + else + return EBTNodeResult::Failed; + + return EBTNodeResult::Succeeded; +} diff --git a/Source/D1/AI/BehaviorTreeNodes/T_TryGetRandomPatrolPoint.h b/Source/D1/AI/BehaviorTreeNodes/T_TryGetRandomPatrolPoint.h new file mode 100644 index 00000000..4b7dc336 --- /dev/null +++ b/Source/D1/AI/BehaviorTreeNodes/T_TryGetRandomPatrolPoint.h @@ -0,0 +1,30 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "BehaviorTree/BTTaskNode.h" +#include "T_TryGetRandomPatrolPoint.generated.h" + +/** + * + */ +UCLASS() +class D1_API UT_TryGetRandomPatrolPoint : public UBTTaskNode +{ + GENERATED_BODY() +public: + UT_TryGetRandomPatrolPoint(); +public: + virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) override; + +private: + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="BlackBoard", meta=(AllowPrivateAccess="true")) + FBlackboardKeySelector BlackboardKey_TargetLocation; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="BlackBoard", meta=(AllowPrivateAccess="true")) + float Radius; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="BlackBoard", meta=(AllowPrivateAccess="true")) + FVector QueryExtent; +}; diff --git a/Source/D1/AI/GruntlingEnemy.cpp b/Source/D1/AI/GruntlingEnemy.cpp index 9ef06868..5974d3d4 100644 --- a/Source/D1/AI/GruntlingEnemy.cpp +++ b/Source/D1/AI/GruntlingEnemy.cpp @@ -61,8 +61,8 @@ void AGruntlingEnemy::BeginPlay() HealthBarComponent->SetWidget(HealthBarRef); } - if(IsValid(IntroAnimMontage)) - PlayAnimMontage(IntroAnimMontage); + //if(IsValid(IntroAnimMontage)) //Intro가 필요하지 않음. 필요할 경우 주석해제 + // PlayAnimMontage(IntroAnimMontage); } void AGruntlingEnemy::OnTargeted(bool bIsTargeted)