Make EnemyCharacters drop EXP Pickup in OnDeath

This commit is contained in:
baz 2024-08-02 02:12:41 +01:00
parent 850ebb973e
commit 0d5858f421
8 changed files with 29 additions and 11 deletions

BIN
Content/Enemy/BP_EnemyCharacter.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/Pickups/BP_EXPPickup.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Pickups/BP_GoldPickup.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Pickups/EXPPickup.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/Pickups/GoldPickup.uasset (Stored with Git LFS)

Binary file not shown.

View File

@ -5,13 +5,13 @@
AEnemyCharacter::AEnemyCharacter(const FObjectInitializer& ObjectInitializer) AEnemyCharacter::AEnemyCharacter(const FObjectInitializer& ObjectInitializer)
{ {
GetHealthComponent()->OnDamaged.BindUFunction(this, "OnDamaged");
GetHealthComponent()->OnDeath.BindUFunction(this, "OnDeath");
} }
void AEnemyCharacter::BeginPlay() void AEnemyCharacter::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
GetHealthComponent()->OnDamaged.BindUFunction(this, "OnDamaged");
GetHealthComponent()->OnDeath.BindUFunction(this, "OnDeath");
} }
void AEnemyCharacter::Tick(float DeltaTime) void AEnemyCharacter::Tick(float DeltaTime)
@ -30,4 +30,14 @@ void AEnemyCharacter::OnDamaged()
void AEnemyCharacter::OnDeath() void AEnemyCharacter::OnDeath()
{ {
//if (IsValid(EXPPickupTemplate))
//{
FActorSpawnParameters actorSpawnParameters;
actorSpawnParameters.Owner = this;
actorSpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
actorSpawnParameters.TransformScaleMethod = ESpawnActorScaleMethod::MultiplyWithRoot;
GetWorld()->SpawnActor<AEXPPickup>(EXPPickupTemplate, GetActorLocation(), FRotator::ZeroRotator,
actorSpawnParameters);
//}
} }

View File

@ -3,6 +3,7 @@
#pragma once #pragma once
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "EXPPickup.h"
#include "VampireCharacter.h" #include "VampireCharacter.h"
#include "BehaviorTree/BehaviorTree.h" #include "BehaviorTree/BehaviorTree.h"
#include "EnemyCharacter.generated.h" #include "EnemyCharacter.generated.h"
@ -15,10 +16,14 @@ class VAMPIRES_API AEnemyCharacter : public AVampireCharacter
{ {
GENERATED_BODY() GENERATED_BODY()
public:
UPROPERTY(EditDefaultsOnly)
TSubclassOf<AEXPPickup> EXPPickupTemplate = nullptr;
private: private:
UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true")) UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true"))
UBehaviorTree* BehaviorTree; UBehaviorTree* BehaviorTree = nullptr;
public: public:
AEnemyCharacter(const FObjectInitializer& ObjectInitializer); AEnemyCharacter(const FObjectInitializer& ObjectInitializer);

View File

@ -60,6 +60,7 @@ void AVampireAIController::OnDamaged(FDamageInfo info)
void AVampireAIController::OnDeath(FDamageInfo info) void AVampireAIController::OnDeath(FDamageInfo info)
{ {
// TODO: Do stuff here // TODO: Do stuff here
EnemyCharacter->OnDeath();
EnemyCharacter->DetachFromControllerPendingDestroy(); EnemyCharacter->DetachFromControllerPendingDestroy();
EnemyCharacter->GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision); EnemyCharacter->GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision);
EnemyCharacter->GetCapsuleComponent()->SetCollisionResponseToAllChannels(ECR_Ignore); EnemyCharacter->GetCapsuleComponent()->SetCollisionResponseToAllChannels(ECR_Ignore);
@ -71,7 +72,6 @@ void AVampireAIController::OnDeath(FDamageInfo info)
characterMovementComponent->SetComponentTickEnabled(false); characterMovementComponent->SetComponentTickEnabled(false);
} }
GetWorldTimerManager().ClearTimer(PawnMoveToTimerHandle); GetWorldTimerManager().ClearTimer(PawnMoveToTimerHandle);
EnemyCharacter->SetLifeSpan(0.1f); EnemyCharacter->SetLifeSpan(0.1f);
} }