Third Person View Character

정재훈·2022년 5월 25일
0

unreal에서 third person view project를 생성하면
3인칭 캐릭터의 기본적인 기능을 거의 구현한 상태로 제공해준다.

Character class를 생성해 처음부터 TPS 3인칭 캐릭터를 구현 한적이
있는데 몇가지 다르게 구현된 것이 있다.
FPS 3인칭 캐릭터 구현

TPS와 RPG에서 3인칭 캐릭터의 차이점

FPS 3인칭은 카메라에 조준점을 캐릭터가 항상 조준하고 있어야 했기 때문에 카메라가 돌아가면 캐릭터의 rotation도 같이 돌아갔다.
3인칭이라 하지만 사실상 1인칭 시점에 spring arm을 뒤로 빼서 3인칭처럼보는 것 뿐이였다.

하지만 TPS와 달리 여러 RPG에서의 3인칭은 카메라를 돌려도 캐릭터는 돌아가지 않아 앞으로 달리면서 옆을보기도하고 캐릭터의 앞모습을 볼수도 있다.

TPS 3인칭에서 RPG 3인칭으로 바꾸기위해서 Character 생성자에 추가해야하는 코드
아래 코드를 추가하면 controller를 돌려도 카메라만 회전하고 캐릭터는 회전하지 않는다.

bUseControllerRotationPitch = false;
bUseControllerRotationYaw = false;
bUseControllerRotationRoll = false;

unreal 3인칭 캐릭터 수정

점프중 회전 수정

기본적으로 제공하는 이 3인칭 캐릭터에 한가지 문제점이 있다.
바로 캐릭터가 점프중에 controller를 돌리면 캐릭터가 공중에서 회전한다는 것이다.
TPS에서는 점프하면서 조준하고 공중에서 뒤로 에임을 돌리기도 하기 때문에 공중에서 회전을 가능하게 하는게 맞다.
하지만 RPG에서 공중에서 캐릭터가 회전하는 게임은 거의 본적이 없는 것같다. 따로 에임이 필요한 무기가 있어서 에임중에 시점이 1인칭으로 바뀌고 공중에서 에임을 돌리는 경우가 있기는 하지만 완전히 3인칭 시점에서 캐릭터가 공중에서 돌아가는 것은 상당히 부자연 스럽다.

따라서 CharacterMovementComponent에 있는 IsMovingOnGround 메소드를 호출한다.
아래코드는 Character가 땅에있으면 true 공중에 떠있으면 false를 반환한다.

#include "GameFramework/CharacterMovementComponent.h"

GetCharacterMovement()->IsMovingOnGround())

위에코드를 MoveForward메소드와 MoveRigth메소드의 조건에 추가해주면 공중에서 회전할수 없게된다.

void AThirdViewCharacter::MoveForward(float Value)
{
	if ((Controller != nullptr) && (Value != 0.0f)&& GetCharacterMovement()->IsMovingOnGround())
	{
		// find out which way is forward
		const FRotator Rotation = Controller->GetControlRotation();
		const FRotator YawRotation(0, Rotation.Yaw, 0);

		// get forward vector
		const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
		AddMovementInput(Direction, Value);
	}
}

void AThirdViewCharacter::MoveRight(float Value)
{
	if ( (Controller != nullptr) && (Value != 0.0f) && GetCharacterMovement()->IsMovingOnGround())
	{
		// find out which way is right
		const FRotator Rotation = Controller->GetControlRotation();
		const FRotator YawRotation(0, Rotation.Yaw, 0);
	
		// get right vector 
		const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
		// add movement in that direction
		AddMovementInput(Direction, Value);
	}
}
profile
게임 개발 공부중!

1개의 댓글

comment-user-thumbnail
2023년 8월 7일

FPS는 3인칭이 없습니다
FPS는 First Person Shooter으로 1인칭을 뜻 합니다
TPS가 Third Person Shooter으로 3인칭을 뜻 합니다

답글 달기