Compare commits

...

4 Commits

Author SHA1 Message Date
e2751c403c 발사체 이동 컴포넌트 2025-04-29 00:34:53 +09:00
b9ab173a18 발사체 생성 2025-04-29 00:10:36 +09:00
9484302667 발사체 생성 2025-04-28 23:54:06 +09:00
b1fcccad48 Projectile 클래스 2025-04-28 23:19:14 +09:00
12 changed files with 116 additions and 17 deletions

BIN
Content/Blueprints/Actors/BP_Projectile.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Content/Maps/Main.umap (Stored with Git LFS)

Binary file not shown.

View File

@ -3,6 +3,7 @@
#include "BasePawn.h" #include "BasePawn.h"
#include "Projectile.h"
#include "Components/CapsuleComponent.h" #include "Components/CapsuleComponent.h"
#include "Kismet/GameplayStatics.h" #include "Kismet/GameplayStatics.h"
@ -50,4 +51,7 @@ void ABasePawn::Fire()
false, false,
3.0 3.0
); );
FVector Location = ProjectileSpawnPoint->GetComponentLocation();
FRotator Rotation = ProjectileSpawnPoint->GetComponentRotation();
GetWorld()->SpawnActor<AProjectile>(ProjectileClass, Location, Rotation);
} }

View File

@ -16,21 +16,31 @@ public:
ABasePawn(); ABasePawn();
protected: protected:
// Rotate Turret to Target Location
void RotateTurret(FVector LookAtTarget); void RotateTurret(FVector LookAtTarget);
// Fire Projectile at Projectile Spawn Point
void Fire(); void Fire();
private: private:
// CapsuleComponent for RootComponent
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Component", meta=(AllowPrivateAccess = "true")) UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Component", meta=(AllowPrivateAccess = "true"))
class UCapsuleComponent* CapsuleComp; class UCapsuleComponent* CapsuleComp;
// Static Mesh Component of Tank Base
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Component", meta=(AllowPrivateAccess = "true")) UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Component", meta=(AllowPrivateAccess = "true"))
UStaticMeshComponent* BaseMesh; UStaticMeshComponent* BaseMesh;
// Static Mesh Component of Rotating part of Tank
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Component", meta=(AllowPrivateAccess = "true")) UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Component", meta=(AllowPrivateAccess = "true"))
UStaticMeshComponent* TurretMesh; UStaticMeshComponent* TurretMesh;
// Scene Component of Projectile Spawn Point
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Component", meta=(AllowPrivateAccess = "true")) UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Component", meta=(AllowPrivateAccess = "true"))
USceneComponent* ProjectileSpawnPoint; USceneComponent* ProjectileSpawnPoint;
// UClass Pointer for Spawn Projectile
UPROPERTY(EditDefaultsOnly, Category = "Combat")
TSubclassOf<class AProjectile> ProjectileClass;
}; };

View File

@ -0,0 +1,33 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "Projectile.h"
#include "GameFramework/ProjectileMovementComponent.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<UStaticMeshComponent>(TEXT("Projectile Mesh"));
RootComponent = ProjectileMesh;
ProjectileMovement = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("Projectile Movement"));
ProjectileMovement->InitialSpeed = 400.0f;
ProjectileMovement->MaxSpeed = 1000.0f;
}
// Called when the game starts or when spawned
void AProjectile::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AProjectile::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}

View File

@ -0,0 +1,34 @@
// 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;
// Projectile Movement Component for Shooting
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Component", meta=(AllowPrivateAccess="true"))
class UProjectileMovementComponent* ProjectileMovement;
};

View File

@ -11,7 +11,6 @@ ATank::ATank()
{ {
SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("SpringArm")); SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("SpringArm"));
SpringArm->SetupAttachment(RootComponent); SpringArm->SetupAttachment(RootComponent);
Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera")); Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
Camera->SetupAttachment(SpringArm); Camera->SetupAttachment(SpringArm);
} }
@ -29,6 +28,7 @@ void ATank::Tick(float DeltaTime)
{ {
Super::Tick(DeltaTime); Super::Tick(DeltaTime);
// Rotate Tank to Mouse Pointer Location
if (PlayerControllerRef) if (PlayerControllerRef)
{ {
FHitResult HitResult; FHitResult HitResult;

View File

@ -28,21 +28,29 @@ protected:
virtual void BeginPlay() override; virtual void BeginPlay() override;
private: private:
// USpringArmComponent for Camera
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Component", meta=(AllowPrivateAccess = "true")) UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Component", meta=(AllowPrivateAccess = "true"))
class USpringArmComponent* SpringArm; class USpringArmComponent* SpringArm;
// UCameraComponent for Camera Component
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Component", meta=(AllowPrivateAccess = "true")) UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Component", meta=(AllowPrivateAccess = "true"))
class UCameraComponent* Camera; class UCameraComponent* Camera;
// Movement speed for Move() operation
UPROPERTY(EditAnywhere, Category = "Movement", BlueprintReadWrite, meta=(AllowPrivateAccess="true")) UPROPERTY(EditAnywhere, Category = "Movement", BlueprintReadWrite, meta=(AllowPrivateAccess="true"))
float Speed = 400.0f; float Speed = 400.0f;
// Turn speed for Turn() operation
UPROPERTY(EditAnywhere, Category = "Movement") UPROPERTY(EditAnywhere, Category = "Movement")
float TurnRate = 45.0f; float TurnRate = 45.0f;
// PlayerController Pointer for Mouse Location Detection
UPROPERTY()
APlayerController* PlayerControllerRef; APlayerController* PlayerControllerRef;
// Move operation through W/S key
void Move(float Value); void Move(float Value);
// Turn operation through A/D key
void Turn(float Value); void Turn(float Value);
}; };

View File

@ -18,10 +18,10 @@ void ATower::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
Tank = Cast<ATank>(UGameplayStatics::GetPlayerPawn(this, 0)); Tank = Cast<ATank>(UGameplayStatics::GetPlayerPawn(this, 0));
GetWorldTimerManager().SetTimer(FireRateTimerHandle, this, &ATower::CheckFireCondition, FireRate, true); GetWorldTimerManager().SetTimer(FireRateTimerHandle, this, &ATower::TryFire, FireRate, true);
} }
void ATower::CheckFireCondition() void ATower::TryFire()
{ {
if (InFireRange()) if (InFireRange())
{ {
@ -29,7 +29,7 @@ void ATower::CheckFireCondition()
} }
} }
bool ATower::InFireRange() bool ATower::InFireRange() const
{ {
if (Tank) if (Tank)
{ {

View File

@ -21,16 +21,23 @@ protected:
virtual void BeginPlay() override; virtual void BeginPlay() override;
private: private:
// Tank Object Pointer which is target
class ATank* Tank; class ATank* Tank;
// Distance to Start Tracking the target
UPROPERTY(EditAnywhere, Category = "Rotate") UPROPERTY(EditAnywhere, Category = "Rotate")
float FireRange = 400; float FireRange = 400.0f;
// FTimerHandle for SetTimer.
FTimerHandle FireRateTimerHandle; FTimerHandle FireRateTimerHandle;
float FireRate = 2.0f;
void CheckFireCondition();
bool InFireRange(); // Fire Period
float FireRate = 2.0f;
// Check Tank is in Range. If so, Fire operation occurs.
void TryFire();
// Check Tank is in Fire Range,
bool InFireRange() const;
}; };