[UE5] TIL - 27 <AddMovementInput, AddControllerPitchInput, AddControllerYawInput, UInputComponent::BindAxis, UInputComponent::BindAction>

ChangJin·2024년 4월 29일
0

Unreal Engine5

목록 보기
55/102
post-thumbnail

2024-04-29

깃허브!
https://github.com/ChangJin-Lee/ARproject
https://github.com/ChangJin-Lee/ToonTank

느낀점
3D 3인칭 게임에서 플레이어의 움직임과 마우스 이동법에 대해서 학습했다. project settings에서 정의해놓은 input axis 와 action을 가져와서 사용했다. 빠르게 플레이어의 이동을 만들 수 있었다.

TIL

  • AddMovementInput, AddControllerPitchInput, AddControllerYawInput
  • UInputComponent::BindAxis, UInputComponent::BindAction

AddMovementInput, AddControllerPitchInput, AddControllerYawInput

https://dev.epicgames.com/documentation/en-us/unreal-engine/API/Runtime/Engine/GameFramework/APawn/AddMovementInput?application_version=5.3
https://dev.epicgames.com/documentation/en-us/unreal-engine/API/Runtime/Engine/GameFramework/APawn/AddControllerPitchInput?application_version=5.3
https://dev.epicgames.com/documentation/en-us/unreal-engine/API/Runtime/Engine/GameFramework/APawn/AddControllerPitchInput?application_version=5.3
https://dev.epicgames.com/documentation/en-us/unreal-engine/API/Runtime/Engine/GameFramework/APawn/AddControllerYawInput?application_version=5.3


  • ScaleValue로 스케일이 된 방향 벡터를 따라서 움직임을 만듭니다. ScaleValue < 0 이면 반대방향입니다. Base Pawn은 움직임을 자동적으로 만들지 않습니다. Tick event에서 유저가 하고자하는 움직임을 만들어 냅니다.
  • Character나 DefaultPawn은 자동적으로 input과 move를 핸들링합니다.

  • 다음처럼 앞으로 가는 함수와 오른쪽으로 가는 함수를 만들 수 있습니다.

  • 헤더파일
private:
	void MoveForward(float AxisValue);
	void MoveRight(float AxisValue);
  • cpp파일
void AShooterCharacter::MoveForward(float AxisValue)
{
	AddMovementInput(GetActorForwardVector() * AxisValue);
}

void AShooterCharacter::MoveRight(float AxisValue)
{
	AddMovementInput(GetActorRightVector() * AxisValue);
}


UInputComponent::BindAxis, UInputComponent::BindAction

https://dev.epicgames.com/documentation/en-us/unreal-engine/API/Runtime/Engine/Components/UInputComponent/BindAxis/2?application_version=5.3
https://dev.epicgames.com/documentation/en-us/unreal-engine/API/Runtime/Engine/Components/UInputComponent/BindAction/2?application_version=5.3

  • c++ 코드에 입력을바인딩합니다.

  • 다음의 템플릿으로 사용합니다.
  • ActionName는 보통 매핑한 인풋의 이름.
  • KeyEvent는 EInputEvent::IE_Pressed 같은 클릭상태
  • Object는 보통 this
  • Func는 함수의 주소값
template<class UserClass>  
FInputActionBinding & BindAction  
&40;  
    const FName ActionName,  
    const EInputEvent KeyEvent,  
    UserClass &42; Object,  
    typename FInputActionHandlerWithKeySignature::TMethodPtr< UserClass > Func  
&41; 

  • SetupPlayerInputComponent에 구현합니다.
// Called to bind functionality to input
void AShooterCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);

	PlayerInputComponent->BindAxis(TEXT("MoveForward"), this, &AShooterCharacter::MoveForward);
	PlayerInputComponent->BindAxis(TEXT("MoveRight"), this, &AShooterCharacter::MoveRight);
	PlayerInputComponent->BindAction(TEXT("Jump"), EInputEvent::IE_Pressed, this, &ACharacter::Jump);
	PlayerInputComponent->BindAxis(TEXT("LookUp"), this, &APawn::AddControllerPitchInput);
	PlayerInputComponent->BindAxis(TEXT("LookRight"), this, &APawn::AddControllerYawInput);
	// PlayerInputComponent->BindAction(TEXT("LookUp"), this, AShooterCharacter::LookUp);
	
}
profile
Unreal Engine 클라이언트 개발자

0개의 댓글