Unreal/Game 2
3. 플레이어 컨트롤러 (바인딩 방법 2개)
kyoun
2019. 6. 15. 22:27
방법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);
}
}
마지막으로 게임모드에서 디폴트 컨트롤러를 지정을 해주면 된다
이외에도 만드는 방법은 매우 많음!