if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red,
TEXT("We are using FPSCharacter!"));
}
축 매핑(Axis Mappings) : 키보드, 마우스, 컨트롤러 입력을 친근한 이름으로 매핑시킨 뒤 나중에 이동 등의 게임 동작에 바인딩 할 수 있음
축 매핑은 지속적으로 풀링되어, 부드러운 전환 및 게임 동작이 가능함
하드웨어 축은 "눌렀다"&"안눌렀다"와 같이 구분되는 것이 아닌 연속적인 입력 수치를 제공함
FPSCharacter.h
UFUNCTION()
void MoveForward(float AxisValue);
UFUNCTION()
void MoveRight(float AxisValue);
FPSCharacter.cpp
AFPSCharacter::SetupPlayerInputComponent()
{
InputComponent->BindAxis("MoveForward", this, &AFPSCharacter::MoveForward);
InputComponent->BindAxis("MoveRight", this, &AFPSCharacter::MoveRight);
}
MoveForward : X축으로 움직이도록
MoveRight : Y축으로 움직이도록
void AFPSCharacter::MoveForward(float AxisValue)
{
FVector Direction = FRotationMatrix(Controller->
GetControlRotation()).GetScaledAxis(EAxis::X);
AddMovementInput(Direction, AxisValue);
}
void AFPSCharacter::MoveRight(float AxisValue)
{
FVector Direction = FRotationMatrix(Controller->
GetControlRotation()).GetScaledAxis(EAxis::Y);
AddMovementInput(Direction, AxisValue);
}
AFPSCharacter::SetupPlayerInputComponent()
{
InputComponent->BindAxis("Turn", this, &AFPSCharacter::AddControllerYawInput);
InputComponent->BindAxis("LookUp", this, &AFPSCharacter::AddControllerPitchInput);
}
FPSChararcter.h
UFUNCTION()
void StartJump();
UFUNCTION()
void StopJump();
FPSCharacter.cpp
void AFPSCharacter::StartJump()
{
bPressedJump = true;
}
void AFPSCharacter::StopJump()
{
bPressedJump = false;
}
InputComponent->BindAction("Jump", IE_Pressed, this, &AFPSCharacter::StartJump);
InputComponent->BindAction("Jump", IE_Released, this, &AFPSCharacter::StopJump);