diff --git a/Content/Blueprints/Actors/BP_Projectile.uasset b/Content/Blueprints/Actors/BP_Projectile.uasset index fa79088..cdfb8f0 100644 Binary files a/Content/Blueprints/Actors/BP_Projectile.uasset and b/Content/Blueprints/Actors/BP_Projectile.uasset differ diff --git a/Content/Blueprints/Pawns/BP_PawnTurret.uasset b/Content/Blueprints/Pawns/BP_PawnTurret.uasset index ebb49e9..6696a9f 100644 Binary files a/Content/Blueprints/Pawns/BP_PawnTurret.uasset and b/Content/Blueprints/Pawns/BP_PawnTurret.uasset differ diff --git a/Content/Blueprints/Pawns/BP_Tank.uasset b/Content/Blueprints/Pawns/BP_Tank.uasset index 9be8fda..1a9cfea 100644 Binary files a/Content/Blueprints/Pawns/BP_Tank.uasset and b/Content/Blueprints/Pawns/BP_Tank.uasset differ diff --git a/Content/Maps/Main.umap b/Content/Maps/Main.umap index 3b31189..7f02b4a 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 12d26c5..3cf47b5 100644 --- a/Source/ToonTanks/BasePawn.cpp +++ b/Source/ToonTanks/BasePawn.cpp @@ -31,7 +31,7 @@ void ABasePawn::RotateTurret(FVector LookAtTarget) FVector ToTarget = LookAtTarget - TurretMesh->GetComponentLocation(); FRotator LookAtRotation = FRotator(0.f, ToTarget.Rotation().Yaw, 0.f); TurretMesh->SetWorldRotation( - FMath::RInterpTo( + FMath::RInterpTo( TurretMesh->GetComponentRotation(), LookAtRotation, UGameplayStatics::GetWorldDeltaSeconds(this), @@ -44,6 +44,7 @@ void ABasePawn::Fire() FVector Location = ProjectileSpawnPoint->GetComponentLocation(); FRotator Rotation = ProjectileSpawnPoint->GetComponentRotation(); + GetWorld()->SpawnActor(ProjectileClass, Location, Rotation); /*DrawDebugSphere( diff --git a/Source/ToonTanks/BasePawn.h b/Source/ToonTanks/BasePawn.h index 5fbfa96..25d8177 100644 --- a/Source/ToonTanks/BasePawn.h +++ b/Source/ToonTanks/BasePawn.h @@ -30,7 +30,7 @@ public: UPROPERTY(EditInstanceOnly) int32 EditInstanceOnlyInt = 14; - + protected: void RotateTurret(FVector LookAtTarget); diff --git a/Source/ToonTanks/HealthComponent.cpp b/Source/ToonTanks/HealthComponent.cpp new file mode 100644 index 0000000..f0b1ad3 --- /dev/null +++ b/Source/ToonTanks/HealthComponent.cpp @@ -0,0 +1,41 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "HealthComponent.h" + +// Sets default values for this component's properties +UHealthComponent::UHealthComponent() +{ + // Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features + // off to improve performance if you don't need them. + PrimaryComponentTick.bCanEverTick = true; + + // ... +} + + +// Called when the game starts +void UHealthComponent::BeginPlay() +{ + Super::BeginPlay(); + + Health = MaxHealth; + + GetOwner()->OnTakeAnyDamage.AddDynamic(this, &UHealthComponent::DamageTaken); + +} + + +// Called every frame +void UHealthComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) +{ + Super::TickComponent(DeltaTime, TickType, ThisTickFunction); + + // ... +} + +void UHealthComponent::DamageTaken(AActor* DamagedActor, float Damage, const UDamageType* DamageType, class AController* Instigator, AActor* DamageCauser) +{ + +} + diff --git a/Source/ToonTanks/HealthComponent.h b/Source/ToonTanks/HealthComponent.h new file mode 100644 index 0000000..0e645d0 --- /dev/null +++ b/Source/ToonTanks/HealthComponent.h @@ -0,0 +1,37 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "Components/ActorComponent.h" +#include "HealthComponent.generated.h" + + +UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) +class TOONTANKS_API UHealthComponent : public UActorComponent +{ + GENERATED_BODY() + +public: + // Sets default values for this component's properties + UHealthComponent(); + +protected: + // Called when the game starts + virtual void BeginPlay() override; + +private: + + UPROPERTY(EditAnywhere, Category = "Health") + float MaxHealth = 100.f; + float Health = 0.f; + + UFUNCTION() + void DamageTaken(AActor* DamagedActor, float Damage, const UDamageType* DamageType, class AController* Instigator, AActor* DamageCauser); + +public: + // Called every frame + virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; + + +}; diff --git a/Source/ToonTanks/Projectile.cpp b/Source/ToonTanks/Projectile.cpp index 92cfe43..5062fe6 100644 --- a/Source/ToonTanks/Projectile.cpp +++ b/Source/ToonTanks/Projectile.cpp @@ -23,6 +23,8 @@ AProjectile::AProjectile() void AProjectile::BeginPlay() { Super::BeginPlay(); + + ProjectileMesh->OnComponentHit.AddDynamic(this, &AProjectile::OnHit); } // Called every frame @@ -31,3 +33,13 @@ void AProjectile::Tick(float DeltaTime) Super::Tick(DeltaTime); } +void AProjectile::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit) +{ + /*UE_LOG(LogTemp, Warning, TEXT("OnHit")); + 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());*/ + + +} + diff --git a/Source/ToonTanks/Projectile.h b/Source/ToonTanks/Projectile.h index c997084..31e60fc 100644 --- a/Source/ToonTanks/Projectile.h +++ b/Source/ToonTanks/Projectile.h @@ -27,6 +27,9 @@ private: UPROPERTY(VisibleAnywhere, Category = "Movement") class UProjectileMovementComponent* ProjectileMovementComponent; + UFUNCTION() + void OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit); + public: // Called every frame virtual void Tick(float DeltaTime) override; diff --git a/Source/ToonTanks/Tank.cpp b/Source/ToonTanks/Tank.cpp index ccec98b..6b1d052 100644 --- a/Source/ToonTanks/Tank.cpp +++ b/Source/ToonTanks/Tank.cpp @@ -21,7 +21,7 @@ ATank::ATank() void ATank::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) { - + Super::SetupPlayerInputComponent(PlayerInputComponent); PlayerInputComponent->BindAxis(TEXT("MoveForward"), this, &ATank::Move); diff --git a/Source/ToonTanks/Tank.h b/Source/ToonTanks/Tank.h index 1ba2fab..3101ff5 100644 --- a/Source/ToonTanks/Tank.h +++ b/Source/ToonTanks/Tank.h @@ -36,7 +36,7 @@ private: UPROPERTY(EditAnywhere, Category = "Movement") float Speed = 200.f; - + UPROPERTY(EditAnywhere, Category = "Movement") float TurnRate = 135.f;