방법1 - 플레이어 캐릭터에서 설정

 

기존에 하던 폰에서 바인딩 방법

void AABCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);

	PlayerInputComponent->BindAxis(TEXT("UpDown"), this, &AABCharacter::UpDown);
	PlayerInputComponent->BindAxis(TEXT("LeftRight"), this, &AABCharacter::LeftRight);
}



 

3.에디터 - 폰 입력 연동, 바인딩

void AABPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) { Super::SetupPlayerInputComponent(PlayerInputComponent); PlayerInputComponent->BindAxis(TEXT("UpDown"),this,&AABPawn:..

kyoun.tistory.com

 



방법2 - 플레이어 컨트롤러에서 설정

 

컨트롤러가 캐릭터 및 폰에 빙의가 되기 때문에 컨트롤러에서 바인딩하고 폰에 적용
나중에 네트워크 처리 할떄도 컨트롤러에서 처리하는 게 좋다고함(?)

/** Allows the PlayerController to set up custom input bindings. */
void AKPlayerController::SetupInputComponent()
{
	Super::SetupInputComponent();

	InputComponent->BindAxis(TEXT("MoveFB"), this, &AKPlayerController::MoveFB);
	InputComponent->BindAxis(TEXT("MoveRL"), this, &AKPlayerController::MoveRL);
	InputComponent->BindAxis(TEXT("Turn"), this, &AKPlayerController::Turn);
}


void AKPlayerController::MoveFB(float NewAxisValue)
{
	APawn* const MyPawn = GetPawn();
	if (MyPawn && NewAxisValue != 0.0f)
	{
		FRotator rot =  GetControlRotation();
		FVector Dir = FRotationMatrix(rot).GetScaledAxis(EAxis::X);

		MyPawn->AddMovementInput(Dir, NewAxisValue);
	}
}

void AKPlayerController::MoveRL(float NewAxisValue)
{
	APawn* const MyPawn = GetPawn();
	if (MyPawn && NewAxisValue != 0.0f)
	{
		FRotator rot = GetControlRotation();
		FVector Dir = FRotationMatrix(rot).GetScaledAxis(EAxis::Y);
		MyPawn->AddMovementInput(Dir, NewAxisValue);
	}
}

void AKPlayerController::Turn(float NewAxisValue)
{
	APawn* const MyPawn = GetPawn();
	if (MyPawn && NewAxisValue != 0.0f)
	{
		FRotator rot = MyPawn->GetControlRotation();
		MyPawn->AddControllerYawInput(NewAxisValue);
	}
}


마지막으로 게임모드에서 디폴트 컨트롤러를 지정을 해주면 된다







이외에도 만드는 방법은 매우 많음!

'Unreal > Game 2 ' 카테고리의 다른 글

4.1 기존 바인딩 함수 이동  (0) 2019.06.18
4. 캐릭터 애니메이션  (0) 2019.06.17
2. 기본 게임모드 및 기본캐릭터 설정  (0) 2019.06.14
1. 게임준비 및 디버깅로그 세팅  (0) 2019.06.14
0. 게임 기획?  (0) 2019.06.14

+ Recent posts