This commit is contained in:
강민제 2025-04-25 22:01:13 +09:00
parent 4aabcd0127
commit 36891ab3d1
5 changed files with 31 additions and 18 deletions

View File

@ -33,7 +33,21 @@ void ABasePawn::RotateTurret(FVector LookAtTarget)
FMath::RInterpTo( FMath::RInterpTo(
TurretMesh->GetComponentRotation(), TurretMesh->GetComponentRotation(),
LookAtRotation, LookAtRotation,
UGameplayStatics::GetWorldDeltaSeconds(this), UGameplayStatics::GetWorldDeltaSeconds(this),
5) 5
); )
);
}
void ABasePawn::Fire()
{
DrawDebugSphere(
GetWorld(),
ProjectileSpawnPoint->GetComponentLocation(),
25,
12,
FColor::Red,
false,
3.0
);
} }

View File

@ -16,9 +16,10 @@ public:
ABasePawn(); ABasePawn();
protected: protected:
void RotateTurret(FVector LookAtTarget); void RotateTurret(FVector LookAtTarget);
void Fire();
private: private:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Component", meta=(AllowPrivateAccess = "true")) UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Component", meta=(AllowPrivateAccess = "true"))
class UCapsuleComponent* CapsuleComp; class UCapsuleComponent* CapsuleComp;

View File

@ -21,6 +21,7 @@ void ATank::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
Super::SetupPlayerInputComponent(PlayerInputComponent); Super::SetupPlayerInputComponent(PlayerInputComponent);
PlayerInputComponent->BindAxis(TEXT("MoveForward"), this, &ATank::Move); PlayerInputComponent->BindAxis(TEXT("MoveForward"), this, &ATank::Move);
PlayerInputComponent->BindAxis(TEXT("Turn"), this, &ATank::Turn); PlayerInputComponent->BindAxis(TEXT("Turn"), this, &ATank::Turn);
PlayerInputComponent->BindAction(TEXT("Fire"), EInputEvent::IE_Pressed, this, &ATank::Fire);
} }
// Called every frame // Called every frame
@ -34,13 +35,15 @@ void ATank::Tick(float DeltaTime)
PlayerControllerRef->GetHitResultUnderCursor( PlayerControllerRef->GetHitResultUnderCursor(
ECollisionChannel::ECC_Visibility, ECollisionChannel::ECC_Visibility,
false, false,
HitResult); HitResult
);
DrawDebugSphere( DrawDebugSphere(
GetWorld(), GetWorld(),
HitResult.ImpactPoint, HitResult.ImpactPoint,
25, 25,
12, 12,
FColor::Green); FColor::Green
);
RotateTurret(HitResult.ImpactPoint); RotateTurret(HitResult.ImpactPoint);
} }
} }
@ -49,7 +52,6 @@ void ATank::Tick(float DeltaTime)
void ATank::BeginPlay() void ATank::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
PlayerControllerRef = Cast<APlayerController>(GetController()); PlayerControllerRef = Cast<APlayerController>(GetController());
} }

View File

@ -8,20 +8,19 @@
void ATower::Tick(float DeltaTime) void ATower::Tick(float DeltaTime)
{ {
Super::Tick(DeltaTime); Super::Tick(DeltaTime);
if (Tank == nullptr)
if (Tank)
{ {
float Distance = FVector::Dist(this->GetActorLocation(), Tank->GetActorLocation()); return;
if (Distance <= FireRange) }
{ float Distance = FVector::Dist(this->GetActorLocation(), Tank->GetActorLocation());
RotateTurret(Tank->GetActorLocation()); if (Distance <= FireRange)
} {
RotateTurret(Tank->GetActorLocation());
} }
} }
void ATower::BeginPlay() void ATower::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
Tank = Cast<ATank>(UGameplayStatics::GetPlayerPawn(this, 0)); Tank = Cast<ATank>(UGameplayStatics::GetPlayerPawn(this, 0));
} }

View File

@ -15,15 +15,12 @@ class TOONTANKS_API ATower : public ABasePawn
GENERATED_BODY() GENERATED_BODY()
public: public:
virtual void Tick(float DeltaTime) override; virtual void Tick(float DeltaTime) override;
protected: protected:
virtual void BeginPlay() override; virtual void BeginPlay() override;
private: private:
class ATank* Tank; class ATank* Tank;
UPROPERTY(EditAnywhere, Category = "Rotate") UPROPERTY(EditAnywhere, Category = "Rotate")