From ff5c2b0a837eccaf59fc08af9e217edcde660ac4 Mon Sep 17 00:00:00 2001 From: 10000Je Date: Fri, 2 May 2025 01:32:17 +0900 Subject: [PATCH] =?UTF-8?q?=EB=8D=B0=EB=AF=B8=EC=A7=80=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Content/Maps/Main.umap | 2 +- Source/ToonTanks/BasePawn.cpp | 3 ++- Source/ToonTanks/HealthComponent.cpp | 5 ++++- Source/ToonTanks/Projectile.cpp | 14 ++++++++++++-- Source/ToonTanks/Projectile.h | 4 ++++ 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/Content/Maps/Main.umap b/Content/Maps/Main.umap index c5c9b51..b38dc68 100644 --- a/Content/Maps/Main.umap +++ b/Content/Maps/Main.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:93a18baabdf9dbbfc9978d78ee5b233577e0f34e8ae2ee75ab17d46fd68fac6a +oid sha256:ffd1f513bbd00b62ee2303251f73810c645dd31cab187591fbccbd1ae122bb3a size 132170 diff --git a/Source/ToonTanks/BasePawn.cpp b/Source/ToonTanks/BasePawn.cpp index 1ddbfff..c957537 100644 --- a/Source/ToonTanks/BasePawn.cpp +++ b/Source/ToonTanks/BasePawn.cpp @@ -44,5 +44,6 @@ void ABasePawn::Fire() { FVector Location = ProjectileSpawnPoint->GetComponentLocation(); FRotator Rotation = ProjectileSpawnPoint->GetComponentRotation(); - GetWorld()->SpawnActor(ProjectileClass, Location, Rotation); + auto Projectile = GetWorld()->SpawnActor(ProjectileClass, Location, Rotation); + Projectile->SetOwner(this); } diff --git a/Source/ToonTanks/HealthComponent.cpp b/Source/ToonTanks/HealthComponent.cpp index 3b93742..e5fa356 100644 --- a/Source/ToonTanks/HealthComponent.cpp +++ b/Source/ToonTanks/HealthComponent.cpp @@ -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) { - UE_LOG(LogTemp, Warning, TEXT("Damage Taken")); + if (Damage <= 0.0f) + return; + Health -= Damage; + UE_LOG(LogTemp, Warning, TEXT("Health: %f"), Health); } diff --git a/Source/ToonTanks/Projectile.cpp b/Source/ToonTanks/Projectile.cpp index 72d1a67..1184522 100644 --- a/Source/ToonTanks/Projectile.cpp +++ b/Source/ToonTanks/Projectile.cpp @@ -4,6 +4,7 @@ #include "Projectile.h" #include "GameFramework/ProjectileMovementComponent.h" +#include "Kismet/GameplayStatics.h" // Sets default values 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) { - UE_LOG(LogTemp, Warning, TEXT("HitComp: %s, Other Actor: %s, Other Comp: %s"), - *HitComp->GetName(), *OtherActor->GetName(), *OtherComp->GetName()); + auto MyOwner = GetOwner(); + 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(); + } } diff --git a/Source/ToonTanks/Projectile.h b/Source/ToonTanks/Projectile.h index 96e2aef..a639ae8 100644 --- a/Source/ToonTanks/Projectile.h +++ b/Source/ToonTanks/Projectile.h @@ -35,4 +35,8 @@ private: // Function for Hit Event UFUNCTION() void OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit); + + // Damage amount for projectile + UPROPERTY(EditAnywhere) + float Damage = 50.0f; };