Action Mappings 에서 일어나는 함수 호출은 한 프레임에 호출이 되는데 , AxisMappings 에서 일어나는 함수는 매 프레임마다 호출이 된다고 한다. ( 계속 누르면 계속 호출된다는 뜻 )
오 ㅋㅋ 콘솔도 고려한다
void AShooterCharacter::MoveForward(float Value)
{
if ((nullptr != Controller) && (0.0f != Value))
{
// find out which way is forward
const FRotator Rotation{ Controller->GetControlRotation() };
const FRotator YawRotation{ 0,Rotation.Yaw,0 };
const FVector Direction{ FRotationMatrix{YawRotation}.GetUnitAxis(EAxis::X) };
AddMovementInput(Direction, Value);
}
}
Controller 의 회전 행렬을 구해서 , Yaw 값만 빼온다. Yaw,Pitch,Roll 값 중에서 Yaw 값을 사용해서
해당 행렬로 X , 앞, 뒤의 벡터를 얻어낸다.
( 아직 행렬에 대한 복기가 필요하니 지금은 그렇구나 정도로만 넘어가자 )
void AShooterCharacter::MoveForward(float Value)
{
if ((nullptr != Controller) && (0.0f != Value))
{
// find out which way is forward
const FRotator Rotation{ Controller->GetControlRotation() };
const FRotator YawRotation{ 0,Rotation.Yaw,0 };
const FVector Direction{ FRotationMatrix{YawRotation}.GetUnitAxis(EAxis::X) };
AddMovementInput(Direction, Value);
}
}
void AShooterCharacter::MoveRight(float Value)
{
if ((nullptr != Controller) && (0.0f != Value))
{
// find out which way is forward
const FRotator Rotation{ Controller->GetControlRotation() };
const FRotator YawRotation{ 0,Rotation.Yaw,0 };
const FVector Direction{ FRotationMatrix{YawRotation}.GetUnitAxis(EAxis::Y) };
AddMovementInput(Direction, Value);
}
}
이동 함수의 주소를 넘겨줘서 바인딩하고 Assert 매크로를 통해서 PlayerInputComponent 를 nullcheck 했다
// Called to bind functionality to input
void AShooterCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
check(PlayerInputComponent);
PlayerInputComponent->BindAxis("MoveForward",this, &AShooterCharacter::MoveForward);
PlayerInputComponent->BindAxis("MoveRight", this, &AShooterCharacter::MoveRight);
}
이까지는.. 혼자서 할 수 있징