diff --git a/Content/Maps/Main.umap b/Content/Maps/Main.umap index 7f02b4a..85dcefc 100644 Binary files a/Content/Maps/Main.umap and b/Content/Maps/Main.umap differ diff --git a/Source/ToonTanks/BasePawn.cpp b/Source/ToonTanks/BasePawn.cpp index 3cf47b5..73ad7be 100644 --- a/Source/ToonTanks/BasePawn.cpp +++ b/Source/ToonTanks/BasePawn.cpp @@ -45,7 +45,8 @@ void ABasePawn::Fire() FRotator Rotation = ProjectileSpawnPoint->GetComponentRotation(); - GetWorld()->SpawnActor(ProjectileClass, Location, Rotation); + auto Projectile = GetWorld()->SpawnActor(ProjectileClass, Location, Rotation); + Projectile->SetOwner(this); /*DrawDebugSphere( GetWorld(), diff --git a/Source/ToonTanks/HealthComponent.cpp b/Source/ToonTanks/HealthComponent.cpp index f0b1ad3..cde3bfd 100644 --- a/Source/ToonTanks/HealthComponent.cpp +++ b/Source/ToonTanks/HealthComponent.cpp @@ -36,6 +36,9 @@ void UHealthComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActo void UHealthComponent::DamageTaken(AActor* DamagedActor, float Damage, const UDamageType* DamageType, class AController* Instigator, AActor* DamageCauser) { + if (Damage <= 0.f) return; + Health -= Damage; + UE_LOG(LogTemp, Warning, TEXT("Health left: %f"), Health); } diff --git a/Source/ToonTanks/Projectile.cpp b/Source/ToonTanks/Projectile.cpp index 5062fe6..b5ee8ef 100644 --- a/Source/ToonTanks/Projectile.cpp +++ b/Source/ToonTanks/Projectile.cpp @@ -4,6 +4,9 @@ #include "Projectile.h" #include "Components/StaticMeshComponent.h" #include "GameFramework/ProjectileMovementComponent.h" +#include "GameFramework/DamageType.h" +#include "Kismet/GameplayStatics.h" +#include "Engine/DamageEvents.h" // Sets default values AProjectile::AProjectile() @@ -39,7 +42,17 @@ void AProjectile::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimi UE_LOG(LogTemp, Warning, TEXT("HitComp: %s"), *HitComp->GetName()); UE_LOG(LogTemp, Warning, TEXT("OtherActor: %s"), *OtherActor->GetName()); UE_LOG(LogTemp, Warning, TEXT("OtherComp: %s"), *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 31e60fc..05788c8 100644 --- a/Source/ToonTanks/Projectile.h +++ b/Source/ToonTanks/Projectile.h @@ -30,6 +30,9 @@ private: UFUNCTION() void OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit); + UPROPERTY(EditAnywhere); + float Damage = 50.f; + public: // Called every frame virtual void Tick(float DeltaTime) override;