데미지 적용

This commit is contained in:
강민제 2025-05-02 01:32:17 +09:00
parent 3d16edc013
commit ff5c2b0a83
5 changed files with 23 additions and 5 deletions

BIN
Content/Maps/Main.umap (Stored with Git LFS)

Binary file not shown.

View File

@ -44,5 +44,6 @@ void ABasePawn::Fire()
{ {
FVector Location = ProjectileSpawnPoint->GetComponentLocation(); FVector Location = ProjectileSpawnPoint->GetComponentLocation();
FRotator Rotation = ProjectileSpawnPoint->GetComponentRotation(); FRotator Rotation = ProjectileSpawnPoint->GetComponentRotation();
GetWorld()->SpawnActor<AProjectile>(ProjectileClass, Location, Rotation); auto Projectile = GetWorld()->SpawnActor<AProjectile>(ProjectileClass, Location, Rotation);
Projectile->SetOwner(this);
} }

View File

@ -33,5 +33,8 @@ void UHealthComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActo
void UHealthComponent::DamageTaken(AActor* DamagedActor, float Damage, const UDamageType* DamageType, AController* Instigator, AActor* DamageCauser) void UHealthComponent::DamageTaken(AActor* DamagedActor, float Damage, const UDamageType* DamageType, AController* Instigator, AActor* DamageCauser)
{ {
UE_LOG(LogTemp, Warning, TEXT("Damage Taken")); if (Damage <= 0.0f)
return;
Health -= Damage;
UE_LOG(LogTemp, Warning, TEXT("Health: %f"), Health);
} }

View File

@ -4,6 +4,7 @@
#include "Projectile.h" #include "Projectile.h"
#include "GameFramework/ProjectileMovementComponent.h" #include "GameFramework/ProjectileMovementComponent.h"
#include "Kismet/GameplayStatics.h"
// Sets default values // Sets default values
AProjectile::AProjectile() AProjectile::AProjectile()
@ -35,8 +36,17 @@ void AProjectile::Tick(float DeltaTime)
void AProjectile::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit) void AProjectile::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{ {
UE_LOG(LogTemp, Warning, TEXT("HitComp: %s, Other Actor: %s, Other Comp: %s"), auto MyOwner = GetOwner();
*HitComp->GetName(), *OtherActor->GetName(), *OtherComp->GetName()); if (MyOwner == nullptr)
return;
auto MyOwnerInstigator = MyOwner->GetInstigatorController();
auto DamageTypeClass = UDamageType::StaticClass();
if (OtherActor && OtherActor != this && OtherActor != MyOwner)
{
UGameplayStatics::ApplyDamage(OtherActor, Damage, MyOwnerInstigator, this, DamageTypeClass);
Destroy();
}
} }

View File

@ -35,4 +35,8 @@ private:
// Function for Hit Event // Function for Hit Event
UFUNCTION() UFUNCTION()
void OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit); void OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit);
// Damage amount for projectile
UPROPERTY(EditAnywhere)
float Damage = 50.0f;
}; };