Update Explosive & AI for Damage Implementation

This commit is contained in:
Rafal Swierczek 2023-10-09 13:37:42 +01:00
parent e3b1d215ef
commit 33b9593f94
7 changed files with 26 additions and 9 deletions

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:69dcd1314353f09d4f12cc1a2a2ced8540f035585740d097a179bb332d850779
size 4545

View File

@ -3,12 +3,14 @@
#include "AICharacter.h"
#include "AI_CompanionController.h"
#include "AI_EnemyController.h"
#include "Components/CapsuleComponent.h"
#include "Engine/DamageEvents.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "Perception/AIPerceptionStimuliSourceComponent.h"
#include "Perception/AISense_Sight.h"
#include "BehaviorTree/BlackboardComponent.h"
#include "Blueprint/AIBlueprintHelperLibrary.h"
// Sets default values
@ -48,12 +50,13 @@ float AAICharacter::TakeDamage(const float DamageAmount, FDamageEvent const& Dam
CurrentHealth -= DamageAmount;
if (CurrentHealth <= 0)
{
if (!IsValid(this)) return 0.0f;
CurrentHealth = 0;
UE_LOG(LogTemp, Display, TEXT("%s is dead"), *CharacterName.ToString());
const AAI_CompanionController* AIController = Cast<AAI_CompanionController>(GetController());
AIController->GetBrainComponent()->StopLogic(*CharacterName.ToString() + FString(" is dead"));
/*const AAI_EnemyController* AIController = Cast<AAI_EnemyController>(GetController());
AIController->GetBrainComponent()->StopLogic(" is dead");*/
this->Tags.Add(FName("Dead"));
//Ragdoll
DetachFromControllerPendingDestroy();
UCapsuleComponent* CapsuleComp = GetCapsuleComponent();

View File

@ -36,6 +36,14 @@ void AAI_EnemyController::OnPossess(APawn* InPawn)
UBlackboardComponent* TempBlackboardPtr;
UseBlackboard(BehaviorTree->BlackboardAsset, TempBlackboardPtr);
Blackboard = TempBlackboardPtr;
if (IsValid(EnemyCharacter->GetPatrolPath()))
{
Blackboard->SetValueAsBool("IsPatroling", true);
}
else
{
Blackboard->SetValueAsBool("IsPatroling", false);
}
RunBehaviorTree(BehaviorTree);
}
}

View File

@ -5,6 +5,8 @@
#include "CollisionDebugDrawingPublic.h"
#include "Kismet/KismetMathLibrary.h"
#include "Engine/DamageEvents.h"
#include "EndlessVendetta/AI/AICharacter.h"
// Sets default values
AExplosive::AExplosive()
@ -69,6 +71,7 @@ void AExplosive::Explosion()
}
// When merged, call philips take damage function here
UE_LOG(LogTemp, Warning, TEXT("A shrapnel piece hit %s, dealing %f damage"), *OutHit.GetActor()->GetName(), DamageToApply);
Cast<AAICharacter>(OutHit.GetActor())->TakeDamage(DamageToApply, FPointDamageEvent(), GetWorld()->GetFirstPlayerController(), this);
}
}
PlayExplosionEffects();