From b1fcccad4823d47aa0c078d508438fd2706a13b3 Mon Sep 17 00:00:00 2001 From: 10000Je Date: Mon, 28 Apr 2025 23:19:14 +0900 Subject: [PATCH] =?UTF-8?q?Projectile=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 --- .../Blueprints/Actors/BP_Projectile.uasset | 3 ++ Source/ToonTanks/BasePawn.cpp | 2 ++ Source/ToonTanks/BasePawn.h | 6 +++- Source/ToonTanks/Projectile.cpp | 28 +++++++++++++++++ Source/ToonTanks/Projectile.h | 31 +++++++++++++++++++ Source/ToonTanks/Tank.cpp | 4 ++- 6 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 Content/Blueprints/Actors/BP_Projectile.uasset create mode 100644 Source/ToonTanks/Projectile.cpp create mode 100644 Source/ToonTanks/Projectile.h diff --git a/Content/Blueprints/Actors/BP_Projectile.uasset b/Content/Blueprints/Actors/BP_Projectile.uasset new file mode 100644 index 0000000..98340bc --- /dev/null +++ b/Content/Blueprints/Actors/BP_Projectile.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bcd81cc45d033298a7bacf3d18ec8fa07e5deaa09c25d47f1212cafbba55ffa8 +size 29909 diff --git a/Source/ToonTanks/BasePawn.cpp b/Source/ToonTanks/BasePawn.cpp index 8c42f79..6012e7d 100644 --- a/Source/ToonTanks/BasePawn.cpp +++ b/Source/ToonTanks/BasePawn.cpp @@ -25,6 +25,7 @@ ABasePawn::ABasePawn() ProjectileSpawnPoint->SetupAttachment(TurretMesh); } +// Rotate Turret to Target Location void ABasePawn::RotateTurret(FVector LookAtTarget) { FVector ToTarget = LookAtTarget - TurretMesh->GetComponentLocation(); @@ -39,6 +40,7 @@ void ABasePawn::RotateTurret(FVector LookAtTarget) ); } +// Fire Projectile at Projectile Spawn Point void ABasePawn::Fire() { DrawDebugSphere( diff --git a/Source/ToonTanks/BasePawn.h b/Source/ToonTanks/BasePawn.h index d22fdbd..161fae0 100644 --- a/Source/ToonTanks/BasePawn.h +++ b/Source/ToonTanks/BasePawn.h @@ -21,15 +21,19 @@ protected: void Fire(); private: + // CapsuleComponent for RootComponent UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Component", meta=(AllowPrivateAccess = "true")) class UCapsuleComponent* CapsuleComp; - + + // Static Mesh Component of Tank Base UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Component", meta=(AllowPrivateAccess = "true")) UStaticMeshComponent* BaseMesh; + // Static Mesh Component of Rotating part of Tank UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Component", meta=(AllowPrivateAccess = "true")) UStaticMeshComponent* TurretMesh; + // Scene Component of Projectile Spawn Point UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Component", meta=(AllowPrivateAccess = "true")) USceneComponent* ProjectileSpawnPoint; diff --git a/Source/ToonTanks/Projectile.cpp b/Source/ToonTanks/Projectile.cpp new file mode 100644 index 0000000..c96e746 --- /dev/null +++ b/Source/ToonTanks/Projectile.cpp @@ -0,0 +1,28 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "Projectile.h" + +// Sets default values +AProjectile::AProjectile() +{ + // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. + PrimaryActorTick.bCanEverTick = false; + ProjectileMesh = CreateDefaultSubobject(TEXT("Projectile Mesh")); + RootComponent = ProjectileMesh; +} + +// Called when the game starts or when spawned +void AProjectile::BeginPlay() +{ + Super::BeginPlay(); + +} + +// Called every frame +void AProjectile::Tick(float DeltaTime) +{ + Super::Tick(DeltaTime); + +} + diff --git a/Source/ToonTanks/Projectile.h b/Source/ToonTanks/Projectile.h new file mode 100644 index 0000000..b7f918f --- /dev/null +++ b/Source/ToonTanks/Projectile.h @@ -0,0 +1,31 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/Actor.h" +#include "Projectile.generated.h" + +UCLASS() +class TOONTANKS_API AProjectile : public AActor +{ + GENERATED_BODY() + +public: + // Sets default values for this actor's properties + AProjectile(); + +protected: + // Called when the game starts or when spawned + virtual void BeginPlay() override; + +public: + // Called every frame + virtual void Tick(float DeltaTime) override; + +private: + // Projectile Static Mesh Component + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Component", meta=(AllowPrivateAccess="true")) + UStaticMeshComponent* ProjectileMesh; + +}; diff --git a/Source/ToonTanks/Tank.cpp b/Source/ToonTanks/Tank.cpp index 8d4eddf..08a29f6 100644 --- a/Source/ToonTanks/Tank.cpp +++ b/Source/ToonTanks/Tank.cpp @@ -11,7 +11,6 @@ ATank::ATank() { SpringArm = CreateDefaultSubobject(TEXT("SpringArm")); SpringArm->SetupAttachment(RootComponent); - Camera = CreateDefaultSubobject(TEXT("Camera")); Camera->SetupAttachment(SpringArm); } @@ -29,6 +28,7 @@ void ATank::Tick(float DeltaTime) { Super::Tick(DeltaTime); + // Rotate Tank to Mouse Pointer Location if (PlayerControllerRef) { FHitResult HitResult; @@ -55,6 +55,7 @@ void ATank::BeginPlay() PlayerControllerRef = Cast(GetController()); } +// Move operation through W/S key void ATank::Move(float Value) { FVector DeltaLocation = FVector::ZeroVector; @@ -63,6 +64,7 @@ void ATank::Move(float Value) this->AddActorLocalOffset(DeltaLocation, true); } +// Turn operation through A/D key void ATank::Turn(float Value) { FRotator DeltaRotation = FRotator::ZeroRotator;