본문 바로가기
Unreal Engine/[Udemy] UE5 Ultimate Shooter

8. 카메라 연결 & 플레이어 이동

by 헛둘이 2023. 3. 28.

이번 강의에서는 카메라 연결과 플레이어 이동 두 가지 기능에 대해 알아봤다.

카메라 연결의 경우는 이전 SpringArm과 비슷하게 헤더 파일을 추가하고 클래스를 선언 및 정의하는 과정이었다.

다만 좀 다른 점은 SetupAttachment 함수에서 연결해주는 부분이 RootComponent가 아닌 SpringArm이라는 것

 

플레이어 이동의 경우 상/하/좌/우 이동하는 기능을 구현했는데,

프로젝트 설정의 입력 란에서 축에 대해 각각 값을 정할 수 있었는데, 예를 들면 Forward는 1, Backward는 -1이었다.

이런 식으로 설정해 준 다음 실제로 AShooterCharacter 클래스에서 멤버함수를 만들어주고, 이 함수들을 바인딩해주는 일련의 과정들을 거치게 되었다.

 

void AShooterCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);
	check(PlayerInputComponent);

	PlayerInputComponent->BindAxis("MoveForward", this, &AShooterCharacter::MoveForward);
	PlayerInputComponent->BindAxis("MoveRight", this, &AShooterCharacter::MoveRight);

}

왠지 std::bind와 std::placeholder를 사용하면 비슷한 구조를 만들 수 있을 것 같다.

 

그리고 MoveComponent라는 컴포넌트를 사용하는데, 사용자 입력이 들어오면 바로 처리하는 게 아니라,

이 MoveComponent를 거치고 정말 그 위치로 이동이 가능하다면 이동한다고 한다.

 

지금 포트폴리오 제작 중인 프로젝트에서도 충분히 써먹을 수 있는 아이디어인 것 같다.

댓글