Unreal - AI (순찰, 전투)

2026. 2. 5. 12:54·Unreal 프로젝트 다이어리/두번째 프로젝트

미리보기

구현내용

1편에서 이어집니다

2026.02.02 - [Unreal 프로젝트 다이어리/두번째 프로젝트] - Unreal - BehaviorTree AI - 1

 

Unreal - BehaviorTree AI - 1

미리보기구현내용플레이어와 전투를 주고받는 AI의 기초설계를 구현하였습니다구현한 AI의 내용은 이와 같습니다AI - Perception + 커스텀범위 시야기반 인식BehaviorTree 를 사용한 AI 설계Blackboard / Tas

lucodev.tistory.com

 

미리 만들어둔 전투시스템을 AI의 BehaviorTree와 연동

그리고 AI의 순찰을 구현하였습니다

 

구현한 내용은 이와 같습니다

  • 간파하기 공격 연동
  • 플레이어가 죽었을때 AI의 행동 연동
  • AI의 Patrol(순찰) 구현

사용클래스

사용 클래스 사용 목적
PatrolPath(액터) AI가 이동할 경로를 정의하는 스플라인 컴포넌트를 가진 액터

 

구현

AI가 SplineComponent로 정의된 경로를 따라 이동하며 순찰하는 Patrol 시스템을 구현

우선 Behavior Tree를 업데이트 시켜주었습니다

 

(어우 이제 노드가 화면에 담기도 버겁습니다)

 

랜덤 패트롤 Task C++ 구현

더보기
#include "T_Patrol.h"
#include "BehaviorTree/BlackboardComponent.h"
#include "AIController.h"
#include "PatrolPath.h"
#include "GameFramework/Pawn.h"
#include "Components/SplineComponent.h"
#include "Navigation/PathFollowingComponent.h"
#include "NavigationSystem.h"

UT_Patrol::UT_Patrol()
{
	NodeName = "Patrol";
	bNotifyTick = true;
	bCreateNodeInstance = true;
}

EBTNodeResult::Type UT_Patrol::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
	FPatrolMemory* memory = (FPatrolMemory*)NodeMemory;

	AAIController* aiCon = OwnerComp.GetAIOwner();
	UBlackboardComponent* blackBoard = OwnerComp.GetBlackboardComponent();

	APatrolPath* path = Cast<APatrolPath>(blackBoard->GetValueAsObject(patrolSplineKey));
	if (!aiCon || !path)
		return EBTNodeResult::Failed;

	FVector loc =path->GetSpline()->GetLocationAtSplinePoint(memory->PatrolIndex,ESplineCoordinateSpace::World);

	FNavPathSharedPtr navPath;
	aiCon->MoveToLocation(loc, acceptanceRadius);

	return EBTNodeResult::InProgress;
}

void UT_Patrol::TickTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, float DeltaSeconds)
{

	UBlackboardComponent* blackBoard = OwnerComp.GetBlackboardComponent();
	if (!blackBoard) 
		return;

	AAIController* aiCon = OwnerComp.GetAIOwner();
	if (!aiCon) 
		return;

	APawn* pawn = aiCon->GetPawn();
	if (!pawn) 
		return;


	APatrolPath* path = Cast<APatrolPath>(blackBoard->GetValueAsObject(patrolSplineKey));
	if (!path || !path->GetSpline()) return;

	UPathFollowingComponent* pathComp = aiCon->GetPathFollowingComponent();
	if (!pathComp) 
		return;

	if (pathComp->GetStatus() == EPathFollowingStatus::Moving)
		return;

	int32 curIdx = blackBoard->GetValueAsInt(patrolIndexKey);
	int32 curDir = blackBoard->GetValueAsInt(patrolDirKey);
	int32 lastIdx = blackBoard->GetValueAsInt(patrolEndKey);

	int32 nextIdx = curIdx + curDir;

	// Ping-Pong 처리
	if (nextIdx > lastIdx)
	{
		curDir = -1;
		nextIdx = lastIdx - 1;
	}
	else if (nextIdx < 0)
	{
		curDir = 1;
		nextIdx = 1;
	}

	blackBoard->SetValueAsInt(patrolIndexKey, nextIdx);
	blackBoard->SetValueAsInt(patrolDirKey, curDir);

	FVector nextLoc = path->GetSpline()->GetLocationAtSplinePoint(nextIdx, ESplineCoordinateSpace::World);
	blackBoard->SetValueAsVector(patrolLocationKey, nextLoc);


	aiCon->MoveToLocation(nextLoc, acceptanceRadius);
}

uint16 UT_Patrol::GetInstanceMemorySize() const
{
	return sizeof(FPatrolMemory);
}

그리고 플레이어의 일반 가드를 무시하는 위험공격 즉 간파하기 시스템을 연동해주었습니다

2026.01.16 - [Unreal 프로젝트 다이어리/두번째 프로젝트] - Unreal - 적 공격 간파하기

 

Unreal - 적 공격 간파하기

미리보기구현내용적의 공격이 위협적이다 라는걸 글자로 표시하면서일반가드로는 가드가 불가능한 위험한 공격을 만들고해당 공격을 간파하는 기능을 구현하였습니다 구현이번글은 전의 가

lucodev.tistory.com

간파하기를 실행할때 적의 오버레이 메테리얼을 조절하여 조금더 위험한 느낌을 연출해봤습니다.

 

 

영상

https://youtu.be/7gk3MJa4nRY

 

저작자표시 비영리 변경금지 (새창열림)

'Unreal 프로젝트 다이어리 > 두번째 프로젝트' 카테고리의 다른 글

Unreal - AI  (0) 2026.02.06
Unreal - AI (EQS Strafe 이동)  (0) 2026.02.06
Unreal - AI (Behavior Tree 설계하기)  (0) 2026.02.02
Unreal - 달리 줌 (Dolly - Zoom)  (0) 2026.01.25
Unreal - 상호작용 추가  (2) 2026.01.24
'Unreal 프로젝트 다이어리/두번째 프로젝트' 카테고리의 다른 글
  • Unreal - AI
  • Unreal - AI (EQS Strafe 이동)
  • Unreal - AI (Behavior Tree 설계하기)
  • Unreal - 달리 줌 (Dolly - Zoom)
lucodev
lucodev
언리얼 포폴개발 일기
  • lucodev
    루코 개발테이블
    lucodev
  • 전체
    오늘
    어제
    • 분류 전체보기 (236)
      • Unreal 프로젝트 다이어리 (132)
        • 첫번째 프로젝트 (73)
        • 두번째 프로젝트 (59)
      • Unreal 팁 (8)
      • Unreal 디버깅 (8)
      • C++ 프로그래머스 (52)
        • Stack,Queue (7)
        • Hash (4)
        • Heap (2)
        • Sort (5)
        • Exhaustive search (5)
        • Greedy (2)
        • BFS , DFS (7)
        • Graph (2)
        • Dynamic Programming (1)
        • C++ Math (2)
        • 기타 문제 (14)
      • C++ 백준 (5)
      • C++ 팁 (1)
      • 개인 코테 & 스타디 <비공개> (29)
        • 코드 개인보관함 (9)
        • 코딩테스트+@ (11)
        • 알고리즘 스타디 (6)
        • 알고리즘 스타디 과제 (3)
        • 비공개 (0)
  • 인기 글

  • 최근 글

  • 최근 댓글

  • 링크

  • 공지사항

  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 태그

    언리얼 컷씬
    unreal 세키로
    unreal
    언리얼 상호작용
    unreal 파쿠르
    언리얼 인터렉션
    unreal npc
    언리얼 behavior tree
    언리얼 파쿠르
    언리얼 인벤토리
    언리얼 비헤이비어트리
    언리얼
    언리얼 parkour
    unreal 인벤토리
    언리얼 세키로
    unreal inventory
    unreal 상호작용
    언리얼 ui
    언리얼 시퀀스
    언리얼 behaviortree
  • hELLO· Designed By정상우.v4.10.3
lucodev
Unreal - AI (순찰, 전투)
상단으로

티스토리툴바