Axis Mappings , Action Mappings

Action Mappings 에서 일어나는 함수 호출은 한 프레임에 호출이 되는데 , AxisMappings 에서 일어나는 함수는 매 프레임마다 호출이 된다고 한다. ( 계속 누르면 계속 호출된다는 뜻 )

Axis Mappings 키 할당

Untitled

오 ㅋㅋ 콘솔도 고려한다

행렬을 통한 이동

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 , 앞, 뒤의 벡터를 얻어낸다. ( 아직 행렬에 대한 복기가 필요하니 지금은 그렇구나 정도로만 넘어가자 )

MoveRight , MoveLeft 함수들

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);
	}
}

Binding Function

이동 함수의 주소를 넘겨줘서 바인딩하고 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);

}

이까지는.. 혼자서 할 수 있징

GIF 2023-02-20 오후 7-34-08.gif