HAxis sos
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
// Project Lab - NHTV Igad
|
||||
|
||||
#include "UnrealProject.h"
|
||||
#include "BTTaskNodeClimb.h"
|
||||
#include "EnemyAIController.h"
|
||||
#include "BehaviorTree/BehaviorTree.h"
|
||||
#include "BehaviorTree/BlackboardComponent.h"
|
||||
#include "BehaviorTree/Blackboard/BlackboardKeyType_Object.h"
|
||||
#include "BehaviorTree/Blackboard/BlackboardKeyType_Vector.h"
|
||||
|
||||
|
||||
UBTTaskNodeClimb::UBTTaskNodeClimb()
|
||||
{
|
||||
NodeName = "Climb";
|
||||
bNotifyTick = true;
|
||||
// accept only actors and vectors
|
||||
BlackboardKey.AddObjectFilter(this, GET_MEMBER_NAME_CHECKED(UBTTaskNodeClimb, BlackboardKey), AActor::StaticClass());
|
||||
BlackboardKey.AddVectorFilter(this, GET_MEMBER_NAME_CHECKED(UBTTaskNodeClimb, BlackboardKey));
|
||||
directionKey.AddVectorFilter(this, GET_MEMBER_NAME_CHECKED(UBTTaskNodeClimb, directionKey));
|
||||
directionKey.AddObjectFilter(this, GET_MEMBER_NAME_CHECKED(UBTTaskNodeClimb, directionKey), AActor::StaticClass());
|
||||
}
|
||||
void UBTTaskNodeClimb::InitializeFromAsset(UBehaviorTree& Asset)
|
||||
{
|
||||
Super::InitializeFromAsset(Asset);
|
||||
|
||||
UBlackboardData &BBAsset = *GetBlackboardAsset();
|
||||
BlackboardKey.ResolveSelectedKey(BBAsset);
|
||||
directionKey.ResolveSelectedKey(BBAsset);
|
||||
}
|
||||
|
||||
EBTNodeResult::Type UBTTaskNodeClimb::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
|
||||
{
|
||||
EBTNodeResult::Type NodeResult = EBTNodeResult::InProgress;
|
||||
NodeResult = PeformClimbTask(OwnerComp, NodeMemory);
|
||||
return NodeResult;
|
||||
}
|
||||
EBTNodeResult::Type UBTTaskNodeClimb::PeformClimbTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
|
||||
{
|
||||
const UBlackboardComponent* MyBlackboard = OwnerComp.GetBlackboardComponent();
|
||||
AAIController* MyController = OwnerComp.GetAIOwner();
|
||||
AEnemyAIController* cont = Cast<AEnemyAIController>(OwnerComp.GetAIOwner());
|
||||
EBTNodeResult::Type NodeResult = EBTNodeResult::Failed;
|
||||
if (cont && MyBlackboard)
|
||||
{
|
||||
const FVector TargetLocation = MyBlackboard->GetValue<UBlackboardKeyType_Vector>(BlackboardKey.GetSelectedKeyID());
|
||||
FVector TargetDirection = FVector::ZeroVector;
|
||||
MyBlackboard->GetLocationFromEntry(directionKey.GetSelectedKeyID(), TargetDirection);
|
||||
|
||||
if (cont->VerticleMoveTo(TargetLocation, TargetDirection,AcceptableRadius ))
|
||||
{
|
||||
NodeResult = EBTNodeResult::Succeeded;
|
||||
}
|
||||
else NodeResult = EBTNodeResult::InProgress;
|
||||
}
|
||||
return NodeResult;
|
||||
}
|
||||
void UBTTaskNodeClimb::TickTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, float DeltaSeconds)
|
||||
{
|
||||
const EBTNodeResult::Type NodeResult = PeformClimbTask(OwnerComp, NodeMemory);
|
||||
if (NodeResult != EBTNodeResult::InProgress)
|
||||
{
|
||||
FinishLatentTask(OwnerComp, NodeResult);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// Project Lab - NHTV Igad
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "BehaviorTree/Tasks/BTTask_BlackboardBase.h"
|
||||
#include "BTTaskNodeClimb.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS(config = Game)
|
||||
class UNREALPROJECT_API UBTTaskNodeClimb : public UBTTaskNode
|
||||
{
|
||||
GENERATED_BODY()
|
||||
public :
|
||||
UPROPERTY(config, Category = Node, EditAnywhere, meta = (ClampMin = "0.0"))
|
||||
float AcceptableRadius;
|
||||
FName GetSelectedBlackboardKey() const;
|
||||
UBTTaskNodeClimb();
|
||||
virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) override;
|
||||
virtual void TickTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, float DeltaSeconds) override;
|
||||
virtual void InitializeFromAsset(UBehaviorTree& Asset) override;
|
||||
UPROPERTY(EditAnywhere, Category = Blackboard)
|
||||
FBlackboardKeySelector directionKey;
|
||||
UPROPERTY(EditAnywhere, Category = Blackboard)
|
||||
FBlackboardKeySelector BlackboardKey;
|
||||
protected:
|
||||
EBTNodeResult::Type PeformClimbTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory);
|
||||
|
||||
|
||||
};
|
||||
|
||||
FORCEINLINE FName UBTTaskNodeClimb::GetSelectedBlackboardKey() const
|
||||
{
|
||||
return directionKey.SelectedKeyName;
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
// Project Lab - NHTV Igad
|
||||
|
||||
#include "UnrealProject.h"
|
||||
#include "BTTaskNodeJumpFence.h"
|
||||
#include "EnemyAIController.h"
|
||||
#include "BehaviorTree/BehaviorTree.h"
|
||||
#include "BehaviorTree/BlackboardComponent.h"
|
||||
#include "BehaviorTree/Blackboard/BlackboardKeyType_Object.h"
|
||||
#include "BehaviorTree/Blackboard/BlackboardKeyType_Vector.h"
|
||||
|
||||
UBTTaskNodeJumpFence::UBTTaskNodeJumpFence()
|
||||
{
|
||||
NodeName = "Jump Fence";
|
||||
bNotifyTick = true;
|
||||
BlackboardKey.AddObjectFilter(this, GET_MEMBER_NAME_CHECKED(UBTTaskNodeJumpFence, BlackboardKey), AActor::StaticClass());
|
||||
BlackboardKey.AddVectorFilter(this, GET_MEMBER_NAME_CHECKED(UBTTaskNodeJumpFence, BlackboardKey));
|
||||
}
|
||||
void UBTTaskNodeJumpFence::InitializeFromAsset(UBehaviorTree& asset)
|
||||
{
|
||||
Super::InitializeFromAsset(asset);
|
||||
UBlackboardData& BBAsset = *GetBlackboardAsset();
|
||||
BlackboardKey.ResolveSelectedKey(BBAsset);
|
||||
}
|
||||
EBTNodeResult::Type UBTTaskNodeJumpFence::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
|
||||
{
|
||||
EBTNodeResult::Type NodeResult = EBTNodeResult::InProgress;
|
||||
NodeResult = PefromJumpFenceTask(OwnerComp, NodeMemory);
|
||||
return NodeResult;
|
||||
}
|
||||
EBTNodeResult::Type UBTTaskNodeJumpFence::PefromJumpFenceTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
|
||||
{
|
||||
const UBlackboardComponent* MyBlackboard = OwnerComp.GetBlackboardComponent();
|
||||
AAIController* MyController = OwnerComp.GetAIOwner();
|
||||
AEnemyAIController* cont = Cast<AEnemyAIController>(OwnerComp.GetAIOwner());
|
||||
EBTNodeResult::Type NodeResult = EBTNodeResult::Failed;
|
||||
if (cont && MyBlackboard)
|
||||
{
|
||||
const FVector TargetLocation = MyBlackboard->GetValue<UBlackboardKeyType_Vector>(BlackboardKey.GetSelectedKeyID());
|
||||
FVector TargetDirection = FVector::ZeroVector;
|
||||
if (cont->JumpFence(TargetLocation))
|
||||
{
|
||||
NodeResult = EBTNodeResult::Succeeded;
|
||||
}
|
||||
else NodeResult = EBTNodeResult::InProgress;
|
||||
}
|
||||
return NodeResult;
|
||||
|
||||
}
|
||||
void UBTTaskNodeJumpFence::TickTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, float DeltaSeconds)
|
||||
{
|
||||
const EBTNodeResult::Type NodeResult = PefromJumpFenceTask(OwnerComp, NodeMemory);
|
||||
if (NodeResult != EBTNodeResult::InProgress)
|
||||
{
|
||||
FinishLatentTask(OwnerComp, NodeResult);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// Project Lab - NHTV Igad
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "BehaviorTree/BTTaskNode.h"
|
||||
#include "BTTaskNodeJumpFence.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class UNREALPROJECT_API UBTTaskNodeJumpFence : public UBTTaskNode
|
||||
{
|
||||
GENERATED_BODY()
|
||||
public:
|
||||
UBTTaskNodeJumpFence();
|
||||
virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) override;
|
||||
virtual void TickTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, float DeltaSeconds) override;
|
||||
virtual void InitializeFromAsset(UBehaviorTree& Asset) override;
|
||||
UPROPERTY(EditAnywhere, Category = Blackboard)
|
||||
FBlackboardKeySelector BlackboardKey;
|
||||
protected:
|
||||
EBTNodeResult::Type PefromJumpFenceTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory);
|
||||
|
||||
};
|
||||
@@ -0,0 +1,178 @@
|
||||
// Project Lab - NHTV Igad
|
||||
|
||||
#include "UnrealProject.h"
|
||||
#include "EnemyAIController.h"
|
||||
#include "EnemyBase.h"
|
||||
#include "NetworkCharacter.h"
|
||||
#include "Navigation/CrowdFollowingComponent.h"
|
||||
|
||||
#include "BehaviorTree/BehaviorTree.h"
|
||||
#include "BehaviorTree/BlackboardComponent.h"
|
||||
|
||||
#include "BehaviorTree/BehaviorTreeComponent.h"
|
||||
#include "BehaviorTree/BlackBoard/BlackboardKeyAllTypes.h"
|
||||
|
||||
#include "DrawDebugHelpers.h"
|
||||
|
||||
AEnemyAIController::AEnemyAIController(const FObjectInitializer& PCIP)
|
||||
//: Super(PCIP.SetDefaultSubobjectClass<UCrowdFollowingComponent>(TEXT("PathFollowingComponent")))
|
||||
{
|
||||
blackBoardComp = CreateDefaultSubobject<UBlackboardComponent>(FName("BlackBoardComp"));
|
||||
behaviorTreeComp = CreateDefaultSubobject<UBehaviorTreeComponent>(FName("BehaviorTreeComp"));
|
||||
climbSpeed = 1.0f;
|
||||
}
|
||||
void AEnemyAIController::Tick(float deltaTime)
|
||||
{
|
||||
Super::Tick(deltaTime);
|
||||
|
||||
}
|
||||
void AEnemyAIController::Possess(APawn* pawn)
|
||||
{
|
||||
Super::Possess(pawn);
|
||||
AEnemyBase* enemy = Cast<AEnemyBase>(pawn);
|
||||
if (enemy &&enemy->treeBehavior)
|
||||
{
|
||||
if (!enemy->treeBehavior->BlackboardAsset)
|
||||
{
|
||||
RERROR("There is no blackboard asset in the behavior tree");
|
||||
return;
|
||||
}
|
||||
blackBoardComp->InitializeBlackboard(*(enemy->treeBehavior->BlackboardAsset));
|
||||
behaviorTreeComp->StartTree(*enemy->treeBehavior);
|
||||
}
|
||||
}
|
||||
bool AEnemyAIController::VerticleMoveTo(FVector destination, FVector direction,float acceptRadius)
|
||||
{
|
||||
FVector location =GetPawn()->GetActorLocation();
|
||||
FVector dest = destination;
|
||||
dest -= location;
|
||||
|
||||
dest *= direction;
|
||||
FVector newDest= dest;
|
||||
float height = newDest.Size();
|
||||
|
||||
|
||||
|
||||
if (height < acceptRadius&&destination.Z <location.Z)
|
||||
{
|
||||
// GetCharacter()->GetCharacterMovement()->GravityScale = 1;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
GetPawn()->SetActorLocation(FVector(location.X+(direction.X*10), location.Y+(direction.Y*10) , (location.Z)+(direction.Z*10)));
|
||||
GetCharacter()->GetCharacterMovement()->GravityScale = 0;
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
bool AEnemyAIController::JumpFence(FVector destination)
|
||||
{
|
||||
TArray<FHitResult> result;
|
||||
UNavigationSystem* navsys = UNavigationSystem::GetCurrent(GetWorld());
|
||||
if (!navsys)
|
||||
{
|
||||
RERROR("There is no navigation system in the current level, please check if there is one or contact a developer!");
|
||||
return false;
|
||||
}
|
||||
ANPCBase* character = Cast<ANPCBase>(GetPawn());
|
||||
FVector direction;
|
||||
FNavLocation navLocation;
|
||||
character->SetActorEnableCollision(false);
|
||||
DrawDebugLine(GetWorld(), GetPawn()->GetActorLocation(), GetPawn()->GetActorLocation() + GetActorUpVector()*-10000.0f, FColor(255, 0, 0),false, -1, 0, 12.333);
|
||||
FCollisionQueryParams collisionParams;
|
||||
collisionParams.AddIgnoredActor(this->GetPawn());
|
||||
GetWorld()->LineTraceMultiByChannel(result, GetPawn()->GetActorLocation(), GetPawn()->GetActorLocation() + GetActorUpVector()*-10000.0f, ECollisionChannel::ECC_WorldStatic, collisionParams);
|
||||
for (int i = 0; i < result.Num(); i++)
|
||||
{
|
||||
|
||||
if(result[i].ImpactPoint!=GetPawn()->GetActorLocation())
|
||||
{
|
||||
if (!navsys->ProjectPointToNavigation(GetPawn()->GetActorLocation(), navLocation))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
GetCharacter()->GetCharacterMovement()->GravityScale = 1;
|
||||
SetBool(false,FName("ClimbKey"));
|
||||
navsys->SimpleMoveToLocation(this,destination);
|
||||
character->PlayNormalAnimation();
|
||||
character->SetActorEnableCollision(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
character->PlayFencAnimation();
|
||||
direction = destination - GetPawn()->GetActorLocation();
|
||||
direction.Normalize();
|
||||
GetPawn()->SetActorLocation(GetPawn()->GetActorLocation()+(direction * 10));
|
||||
return false;
|
||||
}
|
||||
void AEnemyAIController::BeginInactiveState()
|
||||
{
|
||||
Super::BeginInactiveState();
|
||||
}
|
||||
void AEnemyAIController::SetVector(FVector vector, FName name)
|
||||
{
|
||||
if (blackBoardComp)
|
||||
{
|
||||
blackBoardComp->SetValueAsVector(name, (vector));
|
||||
}
|
||||
|
||||
}
|
||||
void AEnemyAIController::SetBool(bool boolean, FName name)
|
||||
{
|
||||
if (blackBoardComp)
|
||||
{
|
||||
blackBoardComp->SetValueAsBool(name, (boolean));
|
||||
}
|
||||
|
||||
}
|
||||
void AEnemyAIController::SetTarget(ANetworkCharacter* player)
|
||||
{
|
||||
if (blackBoardComp)
|
||||
{
|
||||
blackBoardComp->SetValueAsObject((FName("Target")), (player));
|
||||
}
|
||||
}
|
||||
ANetworkCharacter* AEnemyAIController::GetTarget()
|
||||
{
|
||||
if (blackBoardComp)
|
||||
{
|
||||
return Cast<ANetworkCharacter>(blackBoardComp->GetValue<UBlackboardKeyType_Object>(FName("Target")));
|
||||
}
|
||||
return nullptr;
|
||||
|
||||
}
|
||||
|
||||
FVector AEnemyAIController::GetLocationTarget()
|
||||
{
|
||||
if (blackBoardComp)
|
||||
{
|
||||
return FVector(blackBoardComp->GetValue<UBlackboardKeyType_Vector>(FName("TargetLocation")));
|
||||
}
|
||||
return FVector();
|
||||
}
|
||||
|
||||
FVector AEnemyAIController::GetHomeLocation()
|
||||
{
|
||||
if (blackBoardComp)
|
||||
{
|
||||
return FVector(blackBoardComp->GetValue<UBlackboardKeyType_Vector>(FName("HomeLocation")));
|
||||
}
|
||||
return FVector();
|
||||
}
|
||||
FVector AEnemyAIController::GetSelfLocation()
|
||||
{
|
||||
if (blackBoardComp)
|
||||
{
|
||||
return FVector(blackBoardComp->GetValue<UBlackboardKeyType_Vector>(FName("SelfLocation")));
|
||||
}
|
||||
return FVector();
|
||||
}
|
||||
bool AEnemyAIController::GetClimbKey()
|
||||
{
|
||||
if (blackBoardComp)
|
||||
{
|
||||
return blackBoardComp->GetValue<UBlackboardKeyType_Bool>((FName("ClimbKey")));
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
// Project Lab - NHTV Igad
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "AIController.h"
|
||||
#include "EnemyAIController.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class UNREALPROJECT_API AEnemyAIController : public AAIController
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
AEnemyAIController(const FObjectInitializer& PCIP);
|
||||
UPROPERTY(transient)
|
||||
class UBlackboardComponent* blackBoardComp;
|
||||
|
||||
UPROPERTY(transient)
|
||||
class UBehaviorTreeComponent* behaviorTreeComp;
|
||||
UPROPERTY(transient)
|
||||
float climbSpeed;
|
||||
virtual void Tick(float deltaTime)override;
|
||||
virtual void Possess(APawn* pawn) override;
|
||||
virtual void BeginInactiveState() override;
|
||||
bool VerticleMoveTo(FVector destination,FVector direction, float acceptRadius);
|
||||
bool JumpFence(FVector destination);
|
||||
|
||||
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = Behavior)
|
||||
void SetVector(FVector vector, FName name);
|
||||
UFUNCTION(BlueprintCallable, Category = Behavior)
|
||||
void SetBool(bool boolean, FName name);
|
||||
UFUNCTION(BlueprintCallable, Category = Behavior)
|
||||
void SetTarget(class ANetworkCharacter* player);
|
||||
UFUNCTION(BlueprintCallable, Category = Behavior)
|
||||
class ANetworkCharacter* GetTarget();
|
||||
UFUNCTION(BlueprintCallable, Category = Behavior)
|
||||
FVector GetLocationTarget();
|
||||
UFUNCTION(BlueprintCallable, Category = Behavior)
|
||||
FVector GetHomeLocation();
|
||||
UFUNCTION(BlueprintCallable, Category = Behavior)
|
||||
FVector GetSelfLocation();
|
||||
// UFUNCTION(BlueprintCallable, Category = Behavior)
|
||||
// bool GetEnableTree();
|
||||
UFUNCTION(BlueprintCallable, Category = Behavior)
|
||||
bool GetClimbKey();
|
||||
protected:
|
||||
uint8 targetkey;
|
||||
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user