From 4aabcd0127c6e889d5677932e980fc82586dbc86 Mon Sep 17 00:00:00 2001 From: 10000Je Date: Fri, 25 Apr 2025 21:37:57 +0900 Subject: [PATCH] =?UTF-8?q?Tower=20=ED=81=B4=EB=9E=98=EC=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Content/Blueprints/Pawns/BP_PawnTurret.uasset | 4 +-- Source/ToonTanks/Tower.cpp | 27 ++++++++++++++++ Source/ToonTanks/Tower.h | 32 +++++++++++++++++++ 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 Source/ToonTanks/Tower.cpp create mode 100644 Source/ToonTanks/Tower.h diff --git a/Content/Blueprints/Pawns/BP_PawnTurret.uasset b/Content/Blueprints/Pawns/BP_PawnTurret.uasset index 57ce18b..f312497 100644 --- a/Content/Blueprints/Pawns/BP_PawnTurret.uasset +++ b/Content/Blueprints/Pawns/BP_PawnTurret.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6e6ff48b245c6dc3502bea23164cb968190e923db2aa2dd316ffc16d79022e9d -size 33865 +oid sha256:80f2b88b8aacf22db6ac564099014b40fc57c37005353f80cf3b775a41b32a40 +size 34184 diff --git a/Source/ToonTanks/Tower.cpp b/Source/ToonTanks/Tower.cpp new file mode 100644 index 0000000..b7f31c1 --- /dev/null +++ b/Source/ToonTanks/Tower.cpp @@ -0,0 +1,27 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "Tower.h" +#include "Tank.h" +#include "Kismet/GameplayStatics.h" + +void ATower::Tick(float DeltaTime) +{ + Super::Tick(DeltaTime); + + if (Tank) + { + float Distance = FVector::Dist(this->GetActorLocation(), Tank->GetActorLocation()); + if (Distance <= FireRange) + { + RotateTurret(Tank->GetActorLocation()); + } + } +} + +void ATower::BeginPlay() +{ + Super::BeginPlay(); + + Tank = Cast(UGameplayStatics::GetPlayerPawn(this, 0)); +} \ No newline at end of file diff --git a/Source/ToonTanks/Tower.h b/Source/ToonTanks/Tower.h new file mode 100644 index 0000000..fcdf1f0 --- /dev/null +++ b/Source/ToonTanks/Tower.h @@ -0,0 +1,32 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "BasePawn.h" +#include "Tower.generated.h" + +/** + * + */ +UCLASS() +class TOONTANKS_API ATower : public ABasePawn +{ + GENERATED_BODY() + +public: + + virtual void Tick(float DeltaTime) override; + +protected: + + virtual void BeginPlay() override; + +private: + + class ATank* Tank; + + UPROPERTY(EditAnywhere, Category = "Rotate") + float FireRange = 400; + +};