Compare commits
4 Commits
b4912f8f3e
...
e2751c403c
Author | SHA1 | Date | |
---|---|---|---|
e2751c403c | |||
b9ab173a18 | |||
9484302667 | |||
b1fcccad48 |
BIN
Content/Blueprints/Actors/BP_Projectile.uasset
(Stored with Git LFS)
Normal file
BIN
Content/Blueprints/Actors/BP_Projectile.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Content/Blueprints/Pawns/BP_PawnTank.uasset
(Stored with Git LFS)
BIN
Content/Blueprints/Pawns/BP_PawnTank.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Content/Blueprints/Pawns/BP_PawnTurret.uasset
(Stored with Git LFS)
BIN
Content/Blueprints/Pawns/BP_PawnTurret.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Content/Maps/Main.umap
(Stored with Git LFS)
BIN
Content/Maps/Main.umap
(Stored with Git LFS)
Binary file not shown.
@ -3,6 +3,7 @@
|
||||
|
||||
#include "BasePawn.h"
|
||||
|
||||
#include "Projectile.h"
|
||||
#include "Components/CapsuleComponent.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
|
||||
@ -50,4 +51,7 @@ void ABasePawn::Fire()
|
||||
false,
|
||||
3.0
|
||||
);
|
||||
FVector Location = ProjectileSpawnPoint->GetComponentLocation();
|
||||
FRotator Rotation = ProjectileSpawnPoint->GetComponentRotation();
|
||||
GetWorld()->SpawnActor<AProjectile>(ProjectileClass, Location, Rotation);
|
||||
}
|
||||
|
@ -16,21 +16,31 @@ public:
|
||||
ABasePawn();
|
||||
|
||||
protected:
|
||||
// Rotate Turret to Target Location
|
||||
void RotateTurret(FVector LookAtTarget);
|
||||
|
||||
// Fire Projectile at Projectile Spawn Point
|
||||
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;
|
||||
|
||||
// UClass Pointer for Spawn Projectile
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Combat")
|
||||
TSubclassOf<class AProjectile> ProjectileClass;
|
||||
|
||||
};
|
||||
|
33
Source/ToonTanks/Projectile.cpp
Normal file
33
Source/ToonTanks/Projectile.cpp
Normal 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);
|
||||
|
||||
}
|
||||
|
34
Source/ToonTanks/Projectile.h
Normal file
34
Source/ToonTanks/Projectile.h
Normal 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;
|
||||
};
|
@ -11,7 +11,6 @@ ATank::ATank()
|
||||
{
|
||||
SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("SpringArm"));
|
||||
SpringArm->SetupAttachment(RootComponent);
|
||||
|
||||
Camera = CreateDefaultSubobject<UCameraComponent>(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;
|
||||
|
@ -28,21 +28,29 @@ protected:
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
private:
|
||||
// USpringArmComponent for Camera
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Component", meta=(AllowPrivateAccess = "true"))
|
||||
class USpringArmComponent* SpringArm;
|
||||
|
||||
// UCameraComponent for Camera Component
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Component", meta=(AllowPrivateAccess = "true"))
|
||||
class UCameraComponent* Camera;
|
||||
|
||||
// Movement speed for Move() operation
|
||||
UPROPERTY(EditAnywhere, Category = "Movement", BlueprintReadWrite, meta=(AllowPrivateAccess="true"))
|
||||
float Speed = 400.0f;
|
||||
|
||||
// Turn speed for Turn() operation
|
||||
UPROPERTY(EditAnywhere, Category = "Movement")
|
||||
float TurnRate = 45.0f;
|
||||
|
||||
// PlayerController Pointer for Mouse Location Detection
|
||||
UPROPERTY()
|
||||
APlayerController* PlayerControllerRef;
|
||||
|
||||
// Move operation through W/S key
|
||||
void Move(float Value);
|
||||
|
||||
// Turn operation through A/D key
|
||||
void Turn(float Value);
|
||||
};
|
||||
|
@ -18,10 +18,10 @@ void ATower::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
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())
|
||||
{
|
||||
@ -29,7 +29,7 @@ void ATower::CheckFireCondition()
|
||||
}
|
||||
}
|
||||
|
||||
bool ATower::InFireRange()
|
||||
bool ATower::InFireRange() const
|
||||
{
|
||||
if (Tank)
|
||||
{
|
||||
|
@ -21,16 +21,23 @@ protected:
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
private:
|
||||
// Tank Object Pointer which is target
|
||||
class ATank* Tank;
|
||||
|
||||
// Distance to Start Tracking the target
|
||||
UPROPERTY(EditAnywhere, Category = "Rotate")
|
||||
float FireRange = 400;
|
||||
float FireRange = 400.0f;
|
||||
|
||||
// FTimerHandle for SetTimer.
|
||||
FTimerHandle FireRateTimerHandle;
|
||||
|
||||
// Fire Period
|
||||
float FireRate = 2.0f;
|
||||
|
||||
void CheckFireCondition();
|
||||
// Check Tank is in Range. If so, Fire operation occurs.
|
||||
void TryFire();
|
||||
|
||||
bool InFireRange();
|
||||
// Check Tank is in Fire Range,
|
||||
bool InFireRange() const;
|
||||
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user