Pawn
- 플레이어가 조종할 수 있는 Actor
- 움직임을 위해서 애니메이션(리깅(Rigging) 데이터)가 필요하며 스켈러탈 메시라고도 한다.
- 충돌을 고려해 캡슐 컴포넌트를 이해해야 한다.
- 자연스런 움직임을 위해 FloatingPawnMovement, ChrarcterMovement라는 무브먼트를 알아야한다
생성한 Pawn 클래스 업데이트
UCLASS()
class ARENABATTLE_API AABPawn : public APawn
{
// ...
// 충돌기능 감지를 위한 Capsule Component
UPROPERTY(VisibleAnywhere, Category = Collision)
UCapsuleComponent* Capsule;
// 애니메이션을 위한 SkeletalMesh Component
UPROPERTY(VisibleAnywhere, Category = Visual)
USkeletalMeshComponent* Mesh;
// 자연스런 움직임을 위한 FloatingPawnMovement
UPROPERTY(VisibleAnywhere, Category = Movement)
UFloatingPawnMovement* Movement;
// 카메라 위치지정을 위한 SpringArm Component
UPROPERTY(VisibleAnywhere, Category = Camera)
USpringArmComponent* SpringArm;
// Pawn을 촬영할 카메라
UPROPERTY(VisibleAnywhere, Category = Camera)
UCameraComponent* Camera;
AABPawn::AABPawn()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
Capsule = CreateDefaultSubobject<UCapsuleComponent>(TEXT("CAPSULE"));
Mesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("MESH"));
Movement = CreateDefaultSubobject<UFloatingPawnMovement>(TEXT("MOVEMENT"));
SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("SPRINGARM"));
Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("CAMERA"));
RootComponent = Capsule;
Mesh->SetupAttachment(Capsule);
SpringArm->SetupAttachment(Capsule);
Camera->SetupAttachment(SpringArm);
Capsule->SetCapsuleHalfHeight(88.0f);
Capsule->SetCapsuleRadius(34.0f);
Mesh->SetRelativeLocationAndRotation(FVector(0.0f, 0.0f, -88.0f), FRotator(0.0f, -90.0f, 0.0f));
SpringArm->TargetArmLength = 400.0f;
SpringArm->SetRelativeRotation(FRotator(-15.0f, 0.0f, 0.0f));
static ConstructorHelpers::FObjectFinder<USkeletalMesh> SK_CARDBOARD(TEXT("/Game/InfinityBladeWarriors/Character/CompleteCharacters/SK_CharM_Cardboard.SK_CharM_Cardboard"));
if (SK_CARDBOARD.Succeeded())
{
Mesh->SetSkeletalMesh(SK_CARDBOARD.Object);
}
Mesh->SetAnimationMode(EAnimationMode::AnimationBlueprint);
static ConstructorHelpers::FClassFinder<UAnimInstance> WARRIOR_ANIM(TEXT("/Game/Book/Animations/WarriorAnimBlueprint.WarriorAnimBlueprint_C"));
if (WARRIOR_ANIM.Succeeded())
{
Mesh->SetAnimInstanceClass(WARRIOR_ANIM.Class);
}
}
Pawn의 조작을 위햔 키보드 매핑
void AABPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
PlayerInputComponent->BindAxis(TEXT("UpDown"), this, &AABPawn::UpDown);
PlayerInputComponent->BindAxis(TEXT("LeftRight"), this, &AABPawn::LeftRight);
}
void AABPawn::UpDown(float NewAxisValue)
{
AddMovementInput(GetActorForwardVector(), NewAxisValue);
}
void AABPawn::LeftRight(float NewAxisValue)
{
AddMovementInput(GetActorRightVector(), NewAxisValue);
}