언리얼/게임 프로젝트

GameplayAbilitySystem을 이용한 RPG 프로젝트 - (1) 플레이어 블루프린트 생성

monstro 2024. 11. 15. 00:22
728x90
반응형

GameplayAbilitySystem 줄여서 GAS로 불리는 프레임워크는

언리얼에서 제공하며 게임 제작을 유연하게 만들어주는 도구입니다.

 

이를 이용하여 하나의 완성된 게임을 제작해보도록 하겠습니다.

 

*기본적인 구조와 리소스는 Stephen Ulibari님의 강의에서 참고되었음을 알려드립니다*

https://www.udemy.com/course/unreal-engine-5-gas-top-down-rpg/

 

 

플레이어를 세팅하기 이전에 플레이어와 적 모두가 사용할 수 있는 기본적인 클래스

즉, 조상 클래스를 만들고자 합니다.

구성은 다음과 같이 진행됩니다.

 

1) Pawn들의 기본 뼈대인 AuraBaseCharacter

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "AuraCharacterBase.generated.h"

class USkeletalMeshComponent;

UCLASS(Abstract)
class AURA_API AAuraCharacterBase : public ACharacter
{
	GENERATED_BODY()

public:
	AAuraCharacterBase();

protected:
	virtual void BeginPlay() override;

	UPROPERTY(EditAnywhere, Category = "Combat")
	TObjectPtr<USkeletalMeshComponent> Weapon;
};

 

#include "Character/AuraCharacterBase.h"
#include "Components/SkeletalMeshComponent.h"

AAuraCharacterBase::AAuraCharacterBase()
{
	PrimaryActorTick.bCanEverTick = false;

	Weapon = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Weapon"));
	Weapon->SetupAttachment(GetMesh(), FName("WeaponHandSocket"));
	Weapon->SetCollisionEnabled(ECollisionEnabled::NoCollision);
}

void AAuraCharacterBase::BeginPlay()
{
	Super::BeginPlay();
	
}

 

기본적인 Pawn의 구조를 설정하고, 무기를 착용할 수 있는 소켓스켈레탈 메쉬 컴포넌트로 추가합니다.

해당 소켓을 Pawn의 메쉬에 연결하고 소켓이 충돌하지 않게끔 설정하였습니다.

 

위와 같은 조상 클래스에서 상속하여 플레이어를 만들어보겠습니다.

 

2) 플레이어를 위한 AAuraPlayer

#pragma once

#include "CoreMinimal.h"
#include "Character/AuraCharacterBase.h"
#include "AuraPlayer.generated.h"

class USpringArmComponent;
class UCameraComponent;

/**
 * 
 */
UCLASS()
class AURA_API AAuraPlayer : public AAuraCharacterBase
{
	GENERATED_BODY()
	
public:
	AAuraPlayer();

/*
* Camera Section
*/
private:
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, Meta = (AllowPrivateAccess = "true"))
	TObjectPtr<USpringArmComponent> CameraBoom;

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

 

#include "Player/AuraPlayer.h"
#include "Camera/CameraComponent.h"
#include "GameFramework/SpringArmComponent.h"
#include "GameFramework/CharacterMovementComponent.h"

AAuraPlayer::AAuraPlayer()
{
	// Camera
	CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
	CameraBoom->SetupAttachment(RootComponent);
	CameraBoom->TargetArmLength = 700.0f;
	CameraBoom->bInheritYaw = false;
	CameraBoom->bInheritRoll = false;
	CameraBoom->bInheritPitch = false;

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

	// 탑다운 게임을 위한 플레이어 Rotation 설정 
	GetCharacterMovement()->bOrientRotationToMovement = true;
	GetCharacterMovement()->RotationRate = FRotator(0.0f, 400.0f, 0.0f);
	GetCharacterMovement()->bConstrainToPlane = true;
	GetCharacterMovement()->bSnapToPlaneAtStart = true;

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

 

플레이어는 카메라가 있어야 하므로 SpringArm과 Camera를 추가하였습니다.

FollowCamera의 경우, SetupAttachment를 SpringArm의 SocketName으로 설정하는 경우

자동으로 SpringArm의 끝단에 붙게 됩니다.

또한 플레이어의 회전에 따라 카메라가 회전하는 것을 막고자 회전 옵션을 위와 같이 설정하였습니다.

 

또한 CharacterMovement를 반드시 바닥에 붙게끔 고정시켜놓았고,

이에 따라 CharacterMovement도 바닥을 기준으로 갱신됩니다.

 

PlayerController의 회전에 따라 플레이어가 회전하는 옵션을 막았습니다.

최종적으로 아래와 같은 플레이어 블루 프린트를 생성하였습니다.

 

728x90
반응형