그냥 게임개발자

ProjectA - GameMode, Character 클래스 생성 2023/12/26 본문

ProjectA

ProjectA - GameMode, Character 클래스 생성 2023/12/26

sudoju 2023. 12. 26. 17:41

캐릭터 결정

파라곤 TwinBlast

추후에 모델링 바꿀 예정

 

Character : Character에 관련된 클래스

Game : Game에 관련된 클래스

Player : Player입력, Player데이터에 관련된 클래스

 

현재 캐릭터 모듈은 이렇게 두개로 만들었다.

Base는 Character를 상속 받는 클래스

Player는 Base를 상속받는 클래스

 

기본적인 캐릭터 설정값(기획에 따라 바뀔 수도 있음)

PACharacterBase.cpp

#include "Components/CapsuleComponent.h"
#include "GameFramework/CharacterMovementComponent.h"


APACharacterBase::APACharacterBase()
{
	// UseControllerRotation
	bUseControllerRotationPitch = false;
	bUseControllerRotationRoll = false;
	bUseControllerRotationYaw = false;

	// Capsule
	GetCapsuleComponent()->InitCapsuleSize(42.f, 96.f);
	GetCapsuleComponent()->SetCollisionProfileName(TEXT("Pawn"));

	// Movement
	GetCharacterMovement()->bOrientRotationToMovement = true;
	GetCharacterMovement()->RotationRate = FRotator(0.0f, 500.0f, 0.0f);
	GetCharacterMovement()->JumpZVelocity = 700.0f;
	GetCharacterMovement()->AirControl = 0.35f;
	GetCharacterMovement()->MaxWalkSpeed = 500.f;
	GetCharacterMovement()->MinAnalogWalkSpeed = 20.f;
	GetCharacterMovement()->BrakingDecelerationFalling = 2000.0f;

	// Mesh
	GetMesh()->SetRelativeLocationAndRotation(FVector(0.0f, 0.0f, -100.f), FRotator(0.0f, -90.f, 0.0f));
	GetMesh()->SetAnimationMode(EAnimationMode::AnimationBlueprint);
	GetMesh()->SetCollisionProfileName(TEXT("CharacterMesh"));

	// MeshLoad
	static ConstructorHelpers::FObjectFinder<USkeletalMesh> CharacterMeshRef(TEXT("캐릭터스켈레탈메쉬주소"));
	if (CharacterMeshRef.Succeeded())
	{
		GetMesh()->SetSkeletalMesh(CharacterMeshRef.Object);
	}

	static ConstructorHelpers::FClassFinder<UAnimInstance> AnimInstanceClassRef(TEXT("애니메이션인스턴스주소"));
	if (AnimInstanceClassRef.Succeeded())
	{
		GetMesh()->SetAnimInstanceClass(AnimInstanceClassRef.Class);
	}
}

 

 

 

게임모드는 기본적으로 설정할것들만 설정

PAGameModeBase.h

APAGameMode::APAGameMode()
{
	// DefaultPawnClass
	static ConstructorHelpers::FClassFinder<APawn> DefaultPawnClassRef(TEXT("캐릭터 클래스 주소"));
	if (DefaultPawnClassRef.Succeeded())
	{
		DefaultPawnClass = DefaultPawnClassRef.Class;
	}

	//PlayerController
	static ConstructorHelpers::FClassFinder<APlayerController> PlayerControllerClassRef(TEXT("플레이어 컨트롤러 주소"));
	if (PlayerControllerClassRef.Succeeded())
	{
		PlayerControllerClass = PlayerControllerClassRef.Class;
	}
}

 

 

플레이어한테 카메라 생성

PACharacterPlayer.h

	// SpringArm
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, Meta = (AllowPrivateAccess = "true"))
	TObjectPtr<class USpringArmComponent> CameraBoom;

	// Camera
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, Meta = (AllowPrivateAccess = "true"))
	TObjectPtr<class UCameraComponent> FollowCamera;

 

PACharacterPlayer.cpp

#include "Camera/CameraComponent.h"
#include "GameFramework/SpringArmComponent.h"

APACharacterPlayer::APACharacterPlayer()
{
	// SpringArm
	CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
	CameraBoom->SetupAttachment(RootComponent);
	CameraBoom->TargetArmLength = 400.0f;
	CameraBoom->bUsePawnControlRotation = true;


	// Camera
	FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));
	FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName);
	FollowCamera->bUsePawnControlRotation = false;
}