UE4 Character adding Camera & CameraBoom

주홍영·2022년 3월 25일
0

UE4

목록 보기
1/5

ACharacter 클래스를 엔진을 통해 만드는 경우 UskeltalMeshComponent* Mesh variable이 정의되어 있다

ACharacter를 public 상속 받고 있기 때문에 Mesh variable에 접근해서 사용할 수 있다
그전에 meta키워드를 이용해 blueprint에서 사용할 수 있게 만들어준다고 한다
이에 대한 내용은 더 찾아봐야 할 것 같다


이외에도 UCharacterMovementComponent와 UCapsuleComponent등이 존재하고 있음을 알 수 있다
ArrowComponent는 Character가 향하고 있는 방향을 확인할 때 사용하면 된다

그리고 우리는 Camera와 CameraBoom을 이용해 캐릭터의 시야를 만들어 줄 것이다
먼저 Main.h에서 forward declaration으로 두 변수를 만들어 준다

Main.h

	/** Camera boom positioning the camera behind the player */
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
	class USpringArmComponent* CameraBoom;

	/** Follow camera */
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
	class UCameraComponent* FollowCamera;

그리고 Main.cpp에서 constructor에서 CameraBoom, FollowCamera variable을 정의한다

	// Create Camera Boom (pulls toward the player if theres's a collision
	CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
	CameraBoom->SetupAttachment(GetRootComponent());
	CameraBoom->TargetArmLength = 600.f;  // Camera follows at this distance
	CameraBoom->bUsePawnControlRotation = true; // Rotate arm based on controller

	// Create Follow Camera
	FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));
	FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName);
	// Attach the camera to the end of the boom and let the boom adjust to match
	// the controller orientation
	FollowCamera->bUsePawnControlRotation = false;

위의 코드를 build하고 난 후에
Main c++클래스로 blueprint를 만들면 다음과 같이 component들이 생성되었음을 확인할 수 있다

profile
청룡동거주민

0개의 댓글