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(
TurretMesh->GetComponentRotation(),
LookAtRotation,
UGameplayStatics::GetWorldDeltaSeconds(this),
5)
);
UGameplayStatics::GetWorldDeltaSeconds(this),
5
)
);
}
void ABasePawn::Fire()
{
DrawDebugSphere(
GetWorld(),
ProjectileSpawnPoint->GetComponentLocation(),
25,
12,
FColor::Red,
false,
3.0
);
}

View File

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

View File

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

View File

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

View File

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