parent
5352846678
commit
860e2d43cd
|
@ -86,11 +86,11 @@ DoubleClickTime=0.200000
|
|||
+ActionMappings=(ActionName="Aiming",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=RightMouseButton)
|
||||
+ActionMappings=(ActionName="Aiming",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Gamepad_LeftTrigger)
|
||||
+ActionMappings=(ActionName="Select",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=E)
|
||||
+ActionMappings=(ActionName="Select",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Gamepad_FaceButton_Right)
|
||||
+ActionMappings=(ActionName="Select",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Gamepad_FaceButton_Top)
|
||||
+ActionMappings=(ActionName="Reload",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=R)
|
||||
+ActionMappings=(ActionName="Reload",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Gamepad_FaceButton_Left)
|
||||
+ActionMappings=(ActionName="Crouch",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=C)
|
||||
+ActionMappings=(ActionName="Crouch",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Gamepad_RightThumbstick)
|
||||
+ActionMappings=(ActionName="Crouch",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Gamepad_FaceButton_Right)
|
||||
+ActionMappings=(ActionName="FKey",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=F)
|
||||
+ActionMappings=(ActionName="1Key",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=One)
|
||||
+ActionMappings=(ActionName="2Key",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Two)
|
||||
|
@ -114,5 +114,6 @@ DoubleClickTime=0.200000
|
|||
DefaultPlayerInputClass=/Script/EnhancedInput.EnhancedPlayerInput
|
||||
DefaultInputComponentClass=/Script/EnhancedInput.EnhancedInputComponent
|
||||
DefaultTouchInterface=/Engine/MobileResources/HUD/DefaultVirtualJoysticks.DefaultVirtualJoysticks
|
||||
+ConsoleKeys=Tilde
|
||||
-ConsoleKeys=Tilde
|
||||
+ConsoleKeys=`
|
||||
|
||||
|
|
BIN
Content/_Game/Enemies/EnemyBP.uasset (Stored with Git LFS)
BIN
Content/_Game/Enemies/EnemyBP.uasset (Stored with Git LFS)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Content/_Game/Maps/DefaultMap.umap (Stored with Git LFS)
BIN
Content/_Game/Maps/DefaultMap.umap (Stored with Git LFS)
Binary file not shown.
|
@ -9,7 +9,8 @@
|
|||
"Type": "Runtime",
|
||||
"LoadingPhase": "Default",
|
||||
"AdditionalDependencies": [
|
||||
"Engine"
|
||||
"Engine",
|
||||
"AIModule"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
|
|
@ -7,6 +7,10 @@
|
|||
#include "Kismet/GameplayStatics.h"
|
||||
#include "Sound/SoundCue.h"
|
||||
#include "Particles/ParticleSystemComponent.h"
|
||||
#include "Kismet/KismetMathLibrary.h"
|
||||
#include "DrawDebugHelpers.h"
|
||||
#include "EnemyController.h"
|
||||
#include "BehaviorTree/BlackboardComponent.h"
|
||||
|
||||
// Sets default values
|
||||
AEnemy::AEnemy() :
|
||||
|
@ -28,6 +32,19 @@ void AEnemy::BeginPlay()
|
|||
Super::BeginPlay();
|
||||
|
||||
GetMesh()->SetCollisionResponseToChannel(ECollisionChannel::ECC_Visibility, ECollisionResponse::ECR_Block);
|
||||
|
||||
// Get the AI Controller
|
||||
EnemyController = Cast<AEnemyController>(GetController());
|
||||
|
||||
const FVector WorldPatrolPoint = UKismetMathLibrary::TransformLocation(GetActorTransform(), PatrolPoint);
|
||||
DrawDebugSphere(GetWorld(), WorldPatrolPoint, 25.f, 12, FColor::Red, true);
|
||||
|
||||
if (EnemyController)
|
||||
{
|
||||
EnemyController->GetBlackboardComponent()->SetValueAsVector("PatrolPoint", WorldPatrolPoint);
|
||||
EnemyController->RunBehaviorTree(BehaviorTree);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void AEnemy::ShowHealthBar_Implementation()
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
class UParticleSystem;
|
||||
class USoundCue;
|
||||
class UAnimMontage;
|
||||
class UBehaviorTree;
|
||||
class AEnemyController;
|
||||
|
||||
UCLASS()
|
||||
class SHOOTER_API AEnemy : public ACharacter, public IBulletHitInterface
|
||||
|
@ -91,6 +93,16 @@ private:
|
|||
/** Time before a hit number is removed from the screen */
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true))
|
||||
float HitNumberDestroyTime;
|
||||
|
||||
/** Behavior tree for the AI Character */
|
||||
UPROPERTY(EditAnywhere, Category = "Behavior Tree", meta = (AllowPrivateAccess = true))
|
||||
UBehaviorTree* BehaviorTree;
|
||||
|
||||
/** Point for the enemy to move to */
|
||||
UPROPERTY(EditAnywhere, Category = "Behavior Tree", meta = (AllowPrivateAccess = true, MakeEditWidget = true))
|
||||
FVector PatrolPoint;
|
||||
|
||||
AEnemyController* EnemyController;
|
||||
public:
|
||||
// Called every frame
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
|
@ -106,4 +118,6 @@ public:
|
|||
|
||||
UFUNCTION(BlueprintImplementableEvent)
|
||||
void ShowHitNumber(int32 Damage, FVector HitLocation, bool bHeadshot);
|
||||
|
||||
FORCEINLINE UBehaviorTree* GetBehaviorTree() const { return BehaviorTree; }
|
||||
};
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "EnemyController.h"
|
||||
|
||||
#include "Enemy.h"
|
||||
#include "BehaviorTree/BehaviorTree.h"
|
||||
#include "BehaviorTree/BehaviorTreeComponent.h"
|
||||
#include "BehaviorTree/BlackboardComponent.h"
|
||||
|
||||
AEnemyController::AEnemyController()
|
||||
{
|
||||
BlackboardComponent = CreateDefaultSubobject<UBlackboardComponent>(TEXT("BlackboardComponent"));
|
||||
check(BlackboardComponent);
|
||||
|
||||
BehaviorTreeComponent = CreateDefaultSubobject<UBehaviorTreeComponent>(TEXT("BehaviorTreeComponent"));
|
||||
check(BehaviorTreeComponent);
|
||||
}
|
||||
|
||||
void AEnemyController::OnPossess(APawn* InPawn)
|
||||
{
|
||||
Super::OnPossess(InPawn);
|
||||
|
||||
if (!InPawn) return;
|
||||
|
||||
if (AEnemy* Enemy = Cast<AEnemy>(InPawn))
|
||||
{
|
||||
if (Enemy->GetBehaviorTree())
|
||||
{
|
||||
BlackboardComponent->InitializeBlackboard(*(Enemy->GetBehaviorTree()->BlackboardAsset));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "AIController.h"
|
||||
#include "EnemyController.generated.h"
|
||||
|
||||
class UBlackboardComponent;
|
||||
class UBehaviorTreeComponent;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class SHOOTER_API AEnemyController : public AAIController
|
||||
{
|
||||
GENERATED_BODY()
|
||||
public:
|
||||
AEnemyController();
|
||||
virtual void OnPossess(APawn* InPawn) override;
|
||||
|
||||
private:
|
||||
/** Blackboard component for this enemy */
|
||||
UPROPERTY(BlueprintReadWrite, Category = "AI Behavior", meta = (AllowPrivateAccess = true))
|
||||
UBlackboardComponent* BlackboardComponent;
|
||||
|
||||
/** BehaviorTree component for this enemy */
|
||||
UPROPERTY(BlueprintReadWrite, Category = "AI Behavior", meta = (AllowPrivateAccess = true))
|
||||
UBehaviorTreeComponent* BehaviorTreeComponent;
|
||||
|
||||
public:
|
||||
FORCEINLINE UBlackboardComponent* GetBlackboardComponent() const { return BlackboardComponent; }
|
||||
};
|
|
@ -8,7 +8,7 @@ public class Shooter : ModuleRules
|
|||
{
|
||||
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
|
||||
|
||||
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "UMG", "PhysicsCore" });
|
||||
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "UMG", "PhysicsCore", "NavigationSystem", "AIModule" });
|
||||
|
||||
PrivateDependencyModuleNames.AddRange(new string[] { });
|
||||
|
||||
|
|
Loading…
Reference in New Issue