개인프로젝트

[Unreal_C++_DarkSoul]#10_문제 해결, AIController

Hardii2 2022. 12. 25. 09:54

 

[Unreal_C++_DarkSoul]#10_AIController

 

AI의 행동 방식을 정의하는 과정에서 발생한 문제를 해결합니다.

Unreal 포트폴리오 작업 과정을 기록합니다.


 

Overview

 

  1. 문제
  2. 해결

 

문제 

1. AIController::Tick()

void AAIC_CastleKnight::Tick(float DeltaSeconds)
{
	Super::Tick(DeltaSeconds);

	SetFocus(PlayerPawn);
	MoveToActor(PlayerPawn, 100.f);
	if (UKismetMathLibrary::Distance2D(FVector2D(GetPawn()->GetActorLocation()), FVector2D(PlayerPawn->GetActorLocation())) < 240.f)
	{
		Cast<AGameObject>(GetPawn())->Attack();
	}
}

 

Problem

 

  • SetFocus(PlayerPawn)을 통해 AI의 Focal Point를 Player로 설정합니다.
  • 하지만, 게임 플레이 화면에서 Player를 거들떠보지 않는 문제가 발생합니다.

 

해결

1. AIController::Tick()

void AAIC_CastleKnight::Tick(float DeltaSeconds)
{
	Super::Tick(DeltaSeconds);

	// EAIFocusPriority 열거형 추가
	SetFocus(PlayerPawn, EAIFocusPriority::Gameplay);
	MoveToActor(PlayerPawn, 100.f);
	if (UKismetMathLibrary::Distance2D(FVector2D(GetPawn()->GetActorLocation()), FVector2D(PlayerPawn->GetActorLocation())) < 240.f)
	{
		Cast<AGameObject>(GetPawn())->Attack();
	}
}

 

2. EAIFocusPriority 열거형

// the reason for this being namespace instead of a regular enum is
// so that it can be expanded in game-specific code
// @todo this is a bit messy, needs to be refactored
namespace EAIFocusPriority
{
	typedef uint8 Type;

	const Type Default = 0;
	const Type Move = 1;
	const Type Gameplay = 2;

	const Type LastFocusPriority = Gameplay;
}

 

Solution

 

  • SetFocus 함수의 두 번째 인자로 EAIFocusPriority 열거형 멤버를 설정해 줍니다.
  • 귀신 같이 해결됩니다...