그냥 게임개발자
ProjectA - EnhancedInput(Move, Look)(2023/12/26) 본문
일단 강의 들은거랑 내 창작물을 만드는 거랑은 확실히 다르다.

캐릭터를 바꾸었다

이 에셋이다.
Input

Player가 움직일 수 있도록 Move와 Look 함수를 만들어준다.
그다음 위에있는 Action과 MappingContext를 생성하자.
PACharacterPlayer.h
#include "InputActionValue.h"
protected:
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, Meta = (AllowPrivateAccess = "true"))
TObjectPtr<class UInputMappingContext> DefaultMappingContext;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, Meta = (AllowPrivateAccess = "true"))
TObjectPtr<class UInputAction> JumpAction;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, Meta = (AllowPrivateAccess = "true"))
TObjectPtr<class UInputAction> MoveAction;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, Meta = (AllowPrivateAccess = "true"))
TObjectPtr<class UInputAction> LookAction;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, Meta = (AllowPrivateAccess = "true"))
TObjectPtr<class UInputAction> ChangeCameraAction;
void Move(const FInputActionValue& Value);
void Look(const FInputActionValue& Value);
PACharacterPlayer.cpp
#include "InputMappingContext.h"
#include "EnhancedInputComponent.h"
#include "EnhancedInputSubsystems.h"
APACharacterPlayer::APACharacterPlayer()
{
// Input
static ConstructorHelpers::FObjectFinder<UInputMappingContext> DefaultMappingContextRef(TEXT("MappingContext 주소"));
if (DefaultMappingContextRef.Succeeded())
{
DefaultMappingContext = DefaultMappingContextRef.Object;
}
static ConstructorHelpers::FObjectFinder<UInputAction> JumpActionRef(TEXT("Action 주소"));
if (JumpActionRef.Succeeded())
{
JumpAction = JumpActionRef.Object;
}
static ConstructorHelpers::FObjectFinder<UInputAction> MoveActionRef(TEXT("Action 주소"));
if (MoveActionRef.Succeeded())
{
MoveAction = MoveActionRef.Object;
}
static ConstructorHelpers::FObjectFinder<UInputAction> LookActionRef(TEXT("Action 주소"));
if (LookActionRef.Succeeded())
{
LookAction = LookActionRef.Object;
}
static ConstructorHelpers::FObjectFinder<UInputAction> ChangeCameraActionRef(TEXT("Action 주소"));
if (ChangeCameraActionRef.Succeeded())
{
ChangeCameraAction = ChangeCameraActionRef.Object;
}
}
void APACharacterPlayer::BeginPlay()
{
Super::BeginPlay();
// MappingContext
APlayerController* PlayerController = CastChecked<APlayerController>(GetController());
if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PlayerController->GetLocalPlayer()))
{
Subsystem->AddMappingContext(DefaultMappingContext, 0);
}
}
void APACharacterPlayer::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
UEnhancedInputComponent* EnhancedInputComponent = CastChecked<UEnhancedInputComponent>(PlayerInputComponent);
EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Triggered, this, &ACharacter::Jump);
EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Completed, this, &ACharacter::StopJumping);
EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &APACharacterPlayer::Move);
EnhancedInputComponent->BindAction(LookAction, ETriggerEvent::Triggered, this, &APACharacterPlayer::Look);
EnhancedInputComponent->BindAction(ChangeCameraAction, ETriggerEvent::Triggered, this, &APACharacterPlayer::SetChangeCamera);
}
void APACharacterPlayer::Move(const FInputActionValue& Value)
{
FVector2D MovementVector = Value.Get<FVector2D>();
const FRotator Rotation = Controller->GetControlRotation();
const FRotator YawRotation(0, Rotation.Yaw, 0);
const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
AddMovementInput(ForwardDirection, MovementVector.X);
AddMovementInput(RightDirection, MovementVector.Y);
}
void APACharacterPlayer::Look(const FInputActionValue& Value)
{
FVector2D LookAxisVector = Value.Get<FVector2D>();
AddControllerYawInput(LookAxisVector.X);
AddControllerPitchInput(LookAxisVector.Y);
}
향상된 입력 시스템으로 1인칭 카메라, 3인칭 카메라를 바꾸려고 하는데 잘 진행되지 않는다.
오늘 하면서 시간을 많이 소모한 것이 InputAction 설정과 헤더파일이었다...
FInputActionValue라는 구조체를 사용하려면
#include "InputActionValue.h"
이 헤더파일을 추가하거나 EnhancedInputComponent.h파일을 추가해줘야 한다.
그리고 또 까먹을 수 있으니 MappingContext의 설정 스샷을 여기다 남긴다.


필자는 애니메이션은 파라곤애니메이션 그대로 사용했다.
일단은.

결과물은 잘 되는 것 같다.
'ProjectA' 카테고리의 다른 글
ProjectA - 임시적 1인칭 Yaw회전 적용(2023/12/27) (0) | 2023.12.27 |
---|---|
ProjectA - ChangeCamera 에러 수정(2023/12/26) (1) | 2023.12.26 |
ProjectA - GameMode, Character 클래스 생성 2023/12/26 (0) | 2023.12.26 |
프로젝트명 : ProjectA(2023/12/26) (0) | 2023.12.26 |
언리얼 엔진 게임 프레임워크 (0) | 2023.12.26 |