Update AI Characters for Ragdoll on Death
This commit is contained in:
parent
d4b7c4b2d6
commit
8a8421c03f
@ -4,6 +4,8 @@
|
|||||||
#include "CompanionCharacter.h"
|
#include "CompanionCharacter.h"
|
||||||
|
|
||||||
#include "AI_CompanionController.h"
|
#include "AI_CompanionController.h"
|
||||||
|
#include "Components/CapsuleComponent.h"
|
||||||
|
#include "GameFramework/CharacterMovementComponent.h"
|
||||||
#include "Perception/AIPerceptionStimuliSourceComponent.h"
|
#include "Perception/AIPerceptionStimuliSourceComponent.h"
|
||||||
#include "Perception/AISense_Sight.h"
|
#include "Perception/AISense_Sight.h"
|
||||||
|
|
||||||
@ -19,7 +21,6 @@ ACompanionCharacter::ACompanionCharacter()
|
|||||||
void ACompanionCharacter::BeginPlay()
|
void ACompanionCharacter::BeginPlay()
|
||||||
{
|
{
|
||||||
Super::BeginPlay();
|
Super::BeginPlay();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called every frame
|
// Called every frame
|
||||||
@ -39,7 +40,7 @@ UBehaviorTree* ACompanionCharacter::GetBehaviorTree() const
|
|||||||
return BehaviorTree;
|
return BehaviorTree;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ACompanionCharacter::TakeDamage(float DamageAmount)
|
void ACompanionCharacter::TakeDamage(const float DamageAmount)
|
||||||
{
|
{
|
||||||
CurrentHealth -= DamageAmount;
|
CurrentHealth -= DamageAmount;
|
||||||
if (CurrentHealth <= 0)
|
if (CurrentHealth <= 0)
|
||||||
@ -49,6 +50,29 @@ void ACompanionCharacter::TakeDamage(float DamageAmount)
|
|||||||
|
|
||||||
const AAI_CompanionController* AIController = Cast<AAI_CompanionController>(GetController());
|
const AAI_CompanionController* AIController = Cast<AAI_CompanionController>(GetController());
|
||||||
AIController->GetBrainComponent()->StopLogic("Companion is dead");
|
AIController->GetBrainComponent()->StopLogic("Companion is dead");
|
||||||
|
|
||||||
|
//Ragdoll
|
||||||
|
DetachFromControllerPendingDestroy();
|
||||||
|
UCapsuleComponent* CapsuleComp = GetCapsuleComponent();
|
||||||
|
CapsuleComp->SetCollisionEnabled(ECollisionEnabled::NoCollision);
|
||||||
|
CapsuleComp->SetCollisionResponseToAllChannels(ECR_Ignore);
|
||||||
|
|
||||||
|
GetMesh()->SetCollisionProfileName(TEXT("Ragdoll"));
|
||||||
|
SetActorEnableCollision(true);
|
||||||
|
|
||||||
|
GetMesh()->SetAllBodiesSimulatePhysics(true);
|
||||||
|
GetMesh()->SetSimulatePhysics(true);
|
||||||
|
GetMesh()->WakeAllRigidBodies();
|
||||||
|
GetMesh()->bBlendPhysics = true;
|
||||||
|
|
||||||
|
if (UCharacterMovementComponent* CharacterComp = Cast<UCharacterMovementComponent>(GetMovementComponent()))
|
||||||
|
{
|
||||||
|
CharacterComp->StopMovementImmediately();
|
||||||
|
CharacterComp->DisableMovement();
|
||||||
|
CharacterComp->SetComponentTickEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
SetLifeSpan(30.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,4 +85,3 @@ void ACompanionCharacter::SetupStimuliSourceComponent()
|
|||||||
StimuliSourceComponent->RegisterWithPerceptionSystem();
|
StimuliSourceComponent->RegisterWithPerceptionSystem();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
#include "EnemyCharacter.h"
|
#include "EnemyCharacter.h"
|
||||||
|
|
||||||
#include "AI_EnemyController.h"
|
#include "AI_EnemyController.h"
|
||||||
|
#include "Components/CapsuleComponent.h"
|
||||||
|
#include "GameFramework/CharacterMovementComponent.h"
|
||||||
#include "Perception/AIPerceptionStimuliSourceComponent.h"
|
#include "Perception/AIPerceptionStimuliSourceComponent.h"
|
||||||
#include "Perception/AISense_Sight.h"
|
#include "Perception/AISense_Sight.h"
|
||||||
|
|
||||||
@ -21,7 +23,6 @@ AEnemyCharacter::AEnemyCharacter()
|
|||||||
void AEnemyCharacter::BeginPlay()
|
void AEnemyCharacter::BeginPlay()
|
||||||
{
|
{
|
||||||
Super::BeginPlay();
|
Super::BeginPlay();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called every frame
|
// Called every frame
|
||||||
@ -41,7 +42,7 @@ UBehaviorTree* AEnemyCharacter::GetBehaviorTree() const
|
|||||||
return BehaviorTree;
|
return BehaviorTree;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AEnemyCharacter::TakeDamage(float DamageAmount)
|
void AEnemyCharacter::TakeDamage(const float DamageAmount)
|
||||||
{
|
{
|
||||||
CurrentHealth -= DamageAmount;
|
CurrentHealth -= DamageAmount;
|
||||||
if (CurrentHealth <= 0)
|
if (CurrentHealth <= 0)
|
||||||
@ -51,6 +52,29 @@ void AEnemyCharacter::TakeDamage(float DamageAmount)
|
|||||||
|
|
||||||
const AAI_EnemyController* AIController = Cast<AAI_EnemyController>(GetController());
|
const AAI_EnemyController* AIController = Cast<AAI_EnemyController>(GetController());
|
||||||
AIController->GetBrainComponent()->StopLogic("Enemy is dead");
|
AIController->GetBrainComponent()->StopLogic("Enemy is dead");
|
||||||
|
|
||||||
|
//Ragdoll
|
||||||
|
DetachFromControllerPendingDestroy();
|
||||||
|
UCapsuleComponent* CapsuleComp = GetCapsuleComponent();
|
||||||
|
CapsuleComp->SetCollisionEnabled(ECollisionEnabled::NoCollision);
|
||||||
|
CapsuleComp->SetCollisionResponseToAllChannels(ECR_Ignore);
|
||||||
|
|
||||||
|
GetMesh()->SetCollisionProfileName(TEXT("Ragdoll"));
|
||||||
|
SetActorEnableCollision(true);
|
||||||
|
|
||||||
|
GetMesh()->SetAllBodiesSimulatePhysics(true);
|
||||||
|
GetMesh()->SetSimulatePhysics(true);
|
||||||
|
GetMesh()->WakeAllRigidBodies();
|
||||||
|
GetMesh()->bBlendPhysics = true;
|
||||||
|
|
||||||
|
if (UCharacterMovementComponent* CharacterComp = Cast<UCharacterMovementComponent>(GetMovementComponent()))
|
||||||
|
{
|
||||||
|
CharacterComp->StopMovementImmediately();
|
||||||
|
CharacterComp->DisableMovement();
|
||||||
|
CharacterComp->SetComponentTickEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
SetLifeSpan(30.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,4 +87,3 @@ void AEnemyCharacter::SetupStimuliSourceComponent()
|
|||||||
StimuliSourceComponent->RegisterWithPerceptionSystem();
|
StimuliSourceComponent->RegisterWithPerceptionSystem();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,9 @@
|
|||||||
#include "Components/CapsuleComponent.h"
|
#include "Components/CapsuleComponent.h"
|
||||||
#include "EnhancedInputComponent.h"
|
#include "EnhancedInputComponent.h"
|
||||||
#include "EnhancedInputSubsystems.h"
|
#include "EnhancedInputSubsystems.h"
|
||||||
|
#include "AI/EnemyCharacter.h"
|
||||||
#include "GameFramework/CharacterMovementComponent.h"
|
#include "GameFramework/CharacterMovementComponent.h"
|
||||||
|
#include "Kismet/GameplayStatics.h"
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
@ -107,7 +109,7 @@ void AEndlessVendettaCharacter::SetUnCrouch()
|
|||||||
UnCrouch();
|
UnCrouch();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AEndlessVendettaCharacter::TakeDamage(float DamageAmount)
|
void AEndlessVendettaCharacter::TakeDamage(const float DamageAmount)
|
||||||
{
|
{
|
||||||
CurrentHealth -= DamageAmount;
|
CurrentHealth -= DamageAmount;
|
||||||
if (CurrentHealth <= 0)
|
if (CurrentHealth <= 0)
|
||||||
|
@ -76,7 +76,7 @@ public:
|
|||||||
float DefaultHealth = 100.0f;
|
float DefaultHealth = 100.0f;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void BeginPlay();
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
UPROPERTY(EditDefaultsOnly, Category = "Gadget")
|
UPROPERTY(EditDefaultsOnly, Category = "Gadget")
|
||||||
TSubclassOf<AGadgetManager> GadgetManagerClass;
|
TSubclassOf<AGadgetManager> GadgetManagerClass;
|
||||||
|
Loading…
Reference in New Issue
Block a user