diff --git a/EndlessVendetta/Source/EndlessVendetta/AI/CompanionCharacter.cpp b/EndlessVendetta/Source/EndlessVendetta/AI/CompanionCharacter.cpp index a21f7ebd..73ceb453 100644 --- a/EndlessVendetta/Source/EndlessVendetta/AI/CompanionCharacter.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/AI/CompanionCharacter.cpp @@ -4,6 +4,8 @@ #include "CompanionCharacter.h" #include "AI_CompanionController.h" +#include "Components/CapsuleComponent.h" +#include "GameFramework/CharacterMovementComponent.h" #include "Perception/AIPerceptionStimuliSourceComponent.h" #include "Perception/AISense_Sight.h" @@ -19,7 +21,6 @@ ACompanionCharacter::ACompanionCharacter() void ACompanionCharacter::BeginPlay() { Super::BeginPlay(); - } // Called every frame @@ -39,7 +40,7 @@ UBehaviorTree* ACompanionCharacter::GetBehaviorTree() const return BehaviorTree; } -void ACompanionCharacter::TakeDamage(float DamageAmount) +void ACompanionCharacter::TakeDamage(const float DamageAmount) { CurrentHealth -= DamageAmount; if (CurrentHealth <= 0) @@ -49,6 +50,29 @@ void ACompanionCharacter::TakeDamage(float DamageAmount) const AAI_CompanionController* AIController = Cast(GetController()); 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(GetMovementComponent())) + { + CharacterComp->StopMovementImmediately(); + CharacterComp->DisableMovement(); + CharacterComp->SetComponentTickEnabled(false); + } + + SetLifeSpan(30.0f); } } @@ -61,4 +85,3 @@ void ACompanionCharacter::SetupStimuliSourceComponent() StimuliSourceComponent->RegisterWithPerceptionSystem(); } } - diff --git a/EndlessVendetta/Source/EndlessVendetta/AI/EnemyCharacter.cpp b/EndlessVendetta/Source/EndlessVendetta/AI/EnemyCharacter.cpp index feda4730..fa286bc9 100644 --- a/EndlessVendetta/Source/EndlessVendetta/AI/EnemyCharacter.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/AI/EnemyCharacter.cpp @@ -4,6 +4,8 @@ #include "EnemyCharacter.h" #include "AI_EnemyController.h" +#include "Components/CapsuleComponent.h" +#include "GameFramework/CharacterMovementComponent.h" #include "Perception/AIPerceptionStimuliSourceComponent.h" #include "Perception/AISense_Sight.h" @@ -21,7 +23,6 @@ AEnemyCharacter::AEnemyCharacter() void AEnemyCharacter::BeginPlay() { Super::BeginPlay(); - } // Called every frame @@ -41,7 +42,7 @@ UBehaviorTree* AEnemyCharacter::GetBehaviorTree() const return BehaviorTree; } -void AEnemyCharacter::TakeDamage(float DamageAmount) +void AEnemyCharacter::TakeDamage(const float DamageAmount) { CurrentHealth -= DamageAmount; if (CurrentHealth <= 0) @@ -51,6 +52,29 @@ void AEnemyCharacter::TakeDamage(float DamageAmount) const AAI_EnemyController* AIController = Cast(GetController()); 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(GetMovementComponent())) + { + CharacterComp->StopMovementImmediately(); + CharacterComp->DisableMovement(); + CharacterComp->SetComponentTickEnabled(false); + } + + SetLifeSpan(30.0f); } } @@ -63,4 +87,3 @@ void AEnemyCharacter::SetupStimuliSourceComponent() StimuliSourceComponent->RegisterWithPerceptionSystem(); } } - diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp index 17beee4a..736a065c 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp @@ -6,7 +6,9 @@ #include "Components/CapsuleComponent.h" #include "EnhancedInputComponent.h" #include "EnhancedInputSubsystems.h" +#include "AI/EnemyCharacter.h" #include "GameFramework/CharacterMovementComponent.h" +#include "Kismet/GameplayStatics.h" ////////////////////////////////////////////////////////////////////////// @@ -107,7 +109,7 @@ void AEndlessVendettaCharacter::SetUnCrouch() UnCrouch(); } -void AEndlessVendettaCharacter::TakeDamage(float DamageAmount) +void AEndlessVendettaCharacter::TakeDamage(const float DamageAmount) { CurrentHealth -= DamageAmount; if (CurrentHealth <= 0) diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h index 8b690da9..758d92c2 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h @@ -76,7 +76,7 @@ public: float DefaultHealth = 100.0f; protected: - virtual void BeginPlay(); + virtual void BeginPlay() override; UPROPERTY(EditDefaultsOnly, Category = "Gadget") TSubclassOf GadgetManagerClass;