Damage `EnemyCharacter` in `CalculateHits`

This commit is contained in:
Louis Hobbs 2023-02-03 01:31:23 +00:00
parent e06e724c0c
commit 8a54837ad6
2 changed files with 14 additions and 11 deletions

View File

@ -9,6 +9,8 @@
#include "GameFramework/CharacterMovementComponent.h" #include "GameFramework/CharacterMovementComponent.h"
#include "InputMappingContext.h" #include "InputMappingContext.h"
#include "Destructable.h" #include "Destructable.h"
#include "EnemyCharacter.h"
#define COLLISION_WEAPON ECC_GameTraceChannel1 #define COLLISION_WEAPON ECC_GameTraceChannel1
@ -245,17 +247,17 @@ void APlayerCharacter::CalculateHits(TArray<FHitResult>* hits)
// Spawn field actor // Spawn field actor
FTransform transform; FTransform transform;
transform.SetLocation(Result.ImpactPoint); transform.SetLocation(Result.ImpactPoint);
GetWorld()->SpawnActor<AFieldSystemActor>(CurrentWeapon->GetFieldSystemActor(), transform, SpawnParameters); auto field = GetWorld()->SpawnActor<AFieldSystemActor>(CurrentWeapon->GetFieldSystemActor(), transform, SpawnParameters);
fields.Add(field);
if (Result.GetActor()->ActorHasTag(FName("Destructable"))) if (Result.GetActor())
{
if (Result.GetActor()->ActorHasTag("Enemy"))
{ {
// TODO: Do thing // TODO: Do thing
auto destructable = Cast<ADestructable>(Result.GetActor()); auto enemy = Cast<AEnemyCharacter>(Result.GetActor());
destructable->Destruct(); enemy->GetHealthComponent()->TakeDamage(Result.GetActor(),CurrentWeapon->GetWeaponProperties()->WeaponDamage, nullptr, GetController(), this);
} }
else if (Result.GetActor()->ActorHasTag(FName("Enemy")))
{
// TODO: Do thing
} }
} }
} }

View File

@ -9,11 +9,12 @@
#include "EnhancedInputComponent.h" #include "EnhancedInputComponent.h"
#include "NakatomiCharacter.h" #include "NakatomiCharacter.h"
#include "Weapon.h" #include "Weapon.h"
#include "Engine/EngineTypes.h"
#include "Engine/DamageEvents.h"
#include "PlayerCharacter.generated.h" #include "PlayerCharacter.generated.h"
class UInputAction; class UInputAction;
class UInputMappingContext; class UInputMappingContext;
//class UEnhancedInputComponent;
/** /**
* *