포탑(Turret) 회전하기
This commit is contained in:
parent
580ca82639
commit
99c89a2ec2
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/Maps/Main.umap
(Stored with Git LFS)
BIN
Content/Maps/Main.umap
(Stored with Git LFS)
Binary file not shown.
@ -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)
|
||||
);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user