전에 생성한 Bluprint 캐릭터의 설정을 확인하며 cpp로 설정해 준다.
character controller 설정
capsule conponent collision 설정
Mesh Transform 설정
Animation Mode 설정
Mesh Collision 설정
Mesh 설정
이전 글의 Actor와 마찬가지로 Skeletal Mesh의 레페런스를 복사하여 cpp에 넣어준다.
CharacterBase.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "Character/MABCharacterBase.h"
#include "Components/CapsuleComponent.h"
// Sets default values
AMABCharacterBase::AMABCharacterBase()
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
// set controller.
bUseControllerRotationYaw = false;
bUseControllerRotationPitch = false;
bUseControllerRotationRoll = false;
// set capsule collision.
GetCapsuleComponent()->InitCapsuleSize(34.f, 88.f);
GetCapsuleComponent()->SetCollisionProfileName(TEXT("Pawn"));
// set mesh component.
GetMesh()->SetRelativeLocationAndRotation(FVector(0.f, 0.f, -85.f), FRotator(0.f, -90.f, 0.f));
GetMesh()->SetAnimationMode(EAnimationMode::AnimationBlueprint);
GetMesh()->SetCollisionProfileName(TEXT("CharacterMesh"));
// set skeletal mesh.
ConstructorHelpers::FObjectFinder<USkeletalMesh> CharacterMeshRef(TEXT("/Game/XANDRA/Characters/F3/Base/Models/SK_F3_FullCharacter_Quinn_Base.SK_F3_FullCharacter_Quinn_Base"));
if (CharacterMeshRef.Succeeded())
{
GetMesh()->SetSkeletalMesh(CharacterMeshRef.Object);
}
// set animation blueprint.
ConstructorHelpers::FClassFinder<UAnimInstance> AnimInstanceClassRef(TEXT("/Game/Blueprints/Alien/ABP_Alien.ABP_Alien_C"));
if (AnimInstanceClassRef.Succeeded())
{
GetMesh()->SetAnimInstanceClass(AnimInstanceClassRef.Class);
}
}
GameMode.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "Game/MABGameMode.h"
AMABGameMode::AMABGameMode()
{
// set default pawn class.
//ConstructorHelpers::FClassFinder<APawn> AlienClassRef(TEXT("/Game/Blueprints/Alien/BP_Alien.BP_Alien_C"));
//if (AlienClassRef.Succeeded())
//{
// DefaultPawnClass = AlienClassRef.Class;
//}
ConstructorHelpers::FClassFinder<APawn> DefaultAlienClassRef(TEXT("/Script/MAB.MABCharacterPlayer"));
if (DefaultAlienClassRef.Succeeded())
{
DefaultPawnClass = DefaultAlienClassRef.Class;
}
// set player controller class.
ConstructorHelpers::FClassFinder<APlayerController> PlayerControllerClassRef(TEXT("/Script/MAB.MABPlayerController"));
if (PlayerControllerClassRef.Succeeded())
{
PlayerControllerClass = PlayerControllerClassRef.Class;
}
}
결과 화면(카메라X)
SpringArm과 Camera 설정
CharacterPlayer.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Character/MABCharacterBase.h"
#include "MABCharacterPlayer.generated.h"
/**
*
*/
UCLASS()
class MAB_API AMABCharacterPlayer : public AMABCharacterBase
{
GENERATED_BODY()
public:
explicit AMABCharacterPlayer();
// Camera.
protected:
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = Camera, Meta = (AllowPrivateAccess = "true"))
TObjectPtr<class USpringArmComponent> SpringArm;
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = Camera, Meta = (AllowPrivateAccess = "true"))
TObjectPtr<class UCameraComponent> Camera;
};
CharacterPlayer.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "Character/MABCharacterPlayer.h"
#include "GameFramework/SpringArmComponent.h"
#include "Camera/CameraComponent.h"
AMABCharacterPlayer::AMABCharacterPlayer()
{
// Set SpringArm.
SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("SpringArm"));
SpringArm->SetRelativeRotation(FRotator(-40.f, 0.f, 0.f));
SpringArm->SetupAttachment(RootComponent);
SpringArm->TargetArmLength = 500;
SpringArm->bUsePawnControlRotation = true;
SpringArm->bInheritYaw = false;
SpringArm->bInheritPitch = false;
SpringArm->bInheritRoll = false;
// Set Camera.
Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
Camera->SetupAttachment(SpringArm, USpringArmComponent::SocketName); // SpringEndpoint에 카메라가 붙음.
Camera->SetRelativeLocation(FVector(0.f, 0.f, -20.f));
Camera->bUsePawnControlRotation = false;
}
카메라 적용 후 결과 화면
전 내용과 거의 유사하다.
계층구조와 Transform 설정 후,
각 component에 설정해 줬던 부분들을 상속한 component에서 찾아 설정해 준다.
주의할 점은, Rotation 설정에서, FRotator의 매개변수를 잘 확인하고 넣어야 한다.
Pitch, Yaw, Roll 순서로 넣지만, Roll(x축 기준), Pitch(y축 기준), Yaw(z축 기준)이기 때문이다.
'UnrealEngine5 > 프로젝트' 카테고리의 다른 글
[UE5] Blueprint 프로젝트를 C++로 (4) Animation State Machine, Blend Space와 Blend Node (0) | 2025.04.23 |
---|---|
[UE5] Blueprint 프로젝트를 C++로 (3) 마우스 클릭으로 캐릭터 이동하기 (0) | 2025.04.22 |
[UE5] Blueprint 프로젝트를 C++로 만들어보기 (3) 마우스 input 설정 (0) | 2025.04.21 |
[UE5] Blueprint 프로젝트를 C++로 만들어보기 (1) (0) | 2025.04.16 |