발사체 생성
This commit is contained in:
parent
b1fcccad48
commit
9484302667
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.
@ -3,6 +3,7 @@
|
||||
|
||||
#include "BasePawn.h"
|
||||
|
||||
#include "Projectile.h"
|
||||
#include "Components/CapsuleComponent.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
|
||||
@ -25,7 +26,6 @@ ABasePawn::ABasePawn()
|
||||
ProjectileSpawnPoint->SetupAttachment(TurretMesh);
|
||||
}
|
||||
|
||||
// Rotate Turret to Target Location
|
||||
void ABasePawn::RotateTurret(FVector LookAtTarget)
|
||||
{
|
||||
FVector ToTarget = LookAtTarget - TurretMesh->GetComponentLocation();
|
||||
@ -40,7 +40,6 @@ void ABasePawn::RotateTurret(FVector LookAtTarget)
|
||||
);
|
||||
}
|
||||
|
||||
// Fire Projectile at Projectile Spawn Point
|
||||
void ABasePawn::Fire()
|
||||
{
|
||||
DrawDebugSphere(
|
||||
@ -52,4 +51,7 @@ void ABasePawn::Fire()
|
||||
false,
|
||||
3.0
|
||||
);
|
||||
FVector Location = ProjectileSpawnPoint->GetComponentLocation();
|
||||
FRotator Rotation = ProjectileSpawnPoint->GetComponentRotation();
|
||||
GetWorld()->SpawnActor<AProjectile>(ProjectileClass, Location, Rotation);
|
||||
}
|
||||
|
@ -16,8 +16,10 @@ public:
|
||||
ABasePawn();
|
||||
|
||||
protected:
|
||||
// Rotate Turret to Target Location
|
||||
void RotateTurret(FVector LookAtTarget);
|
||||
|
||||
// Fire Projectile at Projectile Spawn Point
|
||||
void Fire();
|
||||
|
||||
private:
|
||||
@ -37,4 +39,7 @@ private:
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Component", meta=(AllowPrivateAccess = "true"))
|
||||
USceneComponent* ProjectileSpawnPoint;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Combat")
|
||||
TSubclassOf<class AProjectile> ProjectileClass;
|
||||
|
||||
};
|
||||
|
@ -55,7 +55,6 @@ void ATank::BeginPlay()
|
||||
PlayerControllerRef = Cast<APlayerController>(GetController());
|
||||
}
|
||||
|
||||
// Move operation through W/S key
|
||||
void ATank::Move(float Value)
|
||||
{
|
||||
FVector DeltaLocation = FVector::ZeroVector;
|
||||
@ -64,7 +63,6 @@ void ATank::Move(float Value)
|
||||
this->AddActorLocalOffset(DeltaLocation, true);
|
||||
}
|
||||
|
||||
// Turn operation through A/D key
|
||||
void ATank::Turn(float Value)
|
||||
{
|
||||
FRotator DeltaRotation = FRotator::ZeroRotator;
|
||||
|
@ -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