HealthComponent
This commit is contained in:
@@ -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<AProjectile>(ProjectileClass, Location, Rotation);
|
||||
|
||||
/*DrawDebugSphere(
|
||||
|
||||
@@ -30,7 +30,7 @@ public:
|
||||
|
||||
UPROPERTY(EditInstanceOnly)
|
||||
int32 EditInstanceOnlyInt = 14;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
void RotateTurret(FVector LookAtTarget);
|
||||
|
||||
41
Source/ToonTanks/HealthComponent.cpp
Normal file
41
Source/ToonTanks/HealthComponent.cpp
Normal file
@@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
37
Source/ToonTanks/HealthComponent.h
Normal file
37
Source/ToonTanks/HealthComponent.h
Normal file
@@ -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;
|
||||
|
||||
|
||||
};
|
||||
@@ -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());*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -21,7 +21,7 @@ ATank::ATank()
|
||||
|
||||
void ATank::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
|
||||
{
|
||||
|
||||
|
||||
Super::SetupPlayerInputComponent(PlayerInputComponent);
|
||||
|
||||
PlayerInputComponent->BindAxis(TEXT("MoveForward"), this, &ATank::Move);
|
||||
|
||||
@@ -36,7 +36,7 @@ private:
|
||||
|
||||
UPROPERTY(EditAnywhere, Category = "Movement")
|
||||
float Speed = 200.f;
|
||||
|
||||
|
||||
UPROPERTY(EditAnywhere, Category = "Movement")
|
||||
float TurnRate = 135.f;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user