Character Movements

정재훈·2022년 5월 6일
0

unreal에서 유저가 컨트롤하는 캐릭터의 움직임을 구현한다.

1. key mapping

조작 input을 받아주기 위해 key mapping해준다

2. binding

// Called to bind functionality to input
void AShooterCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);

	PlayerInputComponent->BindAxis(TEXT("MoveForward"), this, &AShooterCharacter::MoveForward);
	PlayerInputComponent->BindAxis(TEXT("LookUp"), this, &APawn::AddControllerPitchInput);
	PlayerInputComponent->BindAxis(TEXT("LookRight"), this, &APawn::AddControllerYawInput);
	PlayerInputComponent->BindAxis(TEXT("MoveRight"), this, &AShooterCharacter::MoveRight);
	PlayerInputComponent->BindAction(TEXT("JUMP"), EInputEvent::IE_Pressed, this, &ACharacter::Jump);
	PlayerInputComponent->BindAction(TEXT("Shoot"), EInputEvent::IE_Pressed, this, &AShooterCharacter::Shoot);
}

mapping한 key가 input으로 주어지면 클래스에 함수를 호출하도록 binding해준다.
이때 캐릭터를 움직이는 moveForward와 moveRight 함수는 밑에 직접 구현하였고 캐릭터를 회전시키는 lookUp과 LookRight 함수는 Pawn클래스에 원래 구현되어있는 AddControllerYawInput을 호출하도록 했다.

3.Implement movements

void AShooterCharacter::MoveForward(float AxisValue)
{
	AddMovementInput(GetActorForwardVector() * AxisValue);
}

void AShooterCharacter::MoveRight(float AxisValue)
{
	AddMovementInput(GetActorRightVector() * AxisValue);
}
profile
게임 개발 공부중!

0개의 댓글