포탑(Turret) 회전하기

This commit is contained in:
강민제 2025-04-25 20:54:19 +09:00
parent 580ca82639
commit 99c89a2ec2
5 changed files with 23 additions and 13 deletions

Binary file not shown.

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

Binary file not shown.

View File

@ -4,6 +4,7 @@
#include "BasePawn.h"
#include "Components/CapsuleComponent.h"
#include "Kismet/GameplayStatics.h"
// Sets default values
ABasePawn::ABasePawn()
@ -23,3 +24,16 @@ ABasePawn::ABasePawn()
ProjectileSpawnPoint = CreateDefaultSubobject<USceneComponent>(TEXT("Projectile Spawn Point"));
ProjectileSpawnPoint->SetupAttachment(TurretMesh);
}
void ABasePawn::RotateTurret(FVector LookAtTarget)
{
FVector ToTarget = LookAtTarget - TurretMesh->GetComponentLocation();
FRotator LookAtRotation = FRotator(0, ToTarget.Rotation().Yaw, 0);
TurretMesh->SetWorldRotation(
FMath::RInterpTo(
TurretMesh->GetComponentRotation(),
LookAtRotation,
UGameplayStatics::GetWorldDeltaSeconds(this),
5)
);
}

View File

@ -15,6 +15,10 @@ public:
// Sets default values for this pawn's properties
ABasePawn();
protected:
void RotateTurret(FVector LookAtTarget);
private:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Component", meta=(AllowPrivateAccess = "true"))
class UCapsuleComponent* CapsuleComp;

View File

@ -41,7 +41,7 @@ void ATank::Tick(float DeltaTime)
25,
12,
FColor::Green);
RotateTurret(HitResult.ImpactPoint);
}
}
@ -51,14 +51,6 @@ void ATank::BeginPlay()
Super::BeginPlay();
PlayerControllerRef = Cast<APlayerController>(GetController());
DrawDebugSphere(
GetWorld(),
GetActorLocation() + FVector(0, 0, 200),
100,
12,
FColor::Red,
false,
30);
}
void ATank::Move(float Value)