Unreal - Behavior Tree(4) AI Perception Team ID

2025. 5. 4. 20:26·Unreal5 프로젝트 다이어리

현재 AI Perception의 감지 여부는 이렇습니다

적 감지 활성화

중립 감지 활성화

아군감지 비활성화 입니다

 

수정해주겠습니다

중립을 제외시켜줍니다

 

AI 의 컨트롤러에서 .h 에서 IGenericTeamAgentInterface를 상속받습니다

또한 플레이어의 .h에서도 IGenericTeamAgentInterface를 상속받습니다

.h에서 필요한 헤더를 추가해줍니다

#include "GenericTeamAgentInterface.h"

각각 제일 끝에 public IGenericTeamAgentInterface를 추가해줍니다

 

Perception을 사용하는AI의 AI컨트롤러의

.h 에 GetTeamAttitudeTowards와 GetGenericTeamId의 메서드를 정의하기위해 override 해줍니다

virtual ETeamAttitude::Type GetTeamAttitudeTowards(const AActor& Other) const override;
virtual FGenericTeamId GetGenericTeamId() const override;

 

AI는 GenericTeamId를 2번을 가집니다

FGenericTeamId ASkeletonAIController::GetGenericTeamId() const
{
	return FGenericTeamId(2);
}

 

GetTeamAttitudeTowards의 코드입니다

 

ETeamAttitude::Type ASkeletonAIController::GetTeamAttitudeTowards(const AActor& Other) const
{
	const IGenericTeamAgentInterface* otherTeamID = Cast<IGenericTeamAgentInterface>(&Other);
	if (otherTeamID)
	{
		// enemy team id == 1
		if (otherTeamID->GetGenericTeamId() == FGenericTeamId(1)) // 플레이어는 팀 1
		{
			return ETeamAttitude::Hostile;  // enemy
		}
		else
		{
			return ETeamAttitude::Neutral;  // each ai neutral
		}
	}

	// if IGenericTeamAgentInterface Not Have == neutral
	return ETeamAttitude::Neutral;
}

FGenericTeamId ASkeletonAIController::GetGenericTeamId() const
{
	return FGenericTeamId(2);
}

상대의 팀 ID를 비교해서 플레이어 (1) 이면 적대 아니라면(2) 중립을 취합니다

만약 인터페이스를 가지고있으면 중립으로 설정됩니다

GetGenericTeamId에서 자신의 아이디를 설정합니다

AI는 2번 플레이어는 1번으로 설정했습니다

 

플레이어의 .h에서 id를 1번으로 override 하여 로 팀 아이디를 1번으로 설정했습니다

virtual FGenericTeamId GetGenericTeamId() const override
{
	return FGenericTeamId(1);
}

 

이러면 적 AI가 가지고있는 Perception이 적과 아군 중립을 구분을 하게됩니다

'Unreal5 프로젝트 다이어리' 카테고리의 다른 글

Unreal - Behavior Tree(5) 스폰 / 디스폰  (0) 2025.05.08
Unreal - Dissolve Material  (0) 2025.05.08
Unreal - Behavior Tree(3) 플레이어와의 상호작용  (0) 2025.05.02
Unreal - Behavior Tree(2) 플레이어 따라가기  (0) 2025.04.29
Unreal - BehaviorTree(1) AI Perception  (0) 2025.04.27
'Unreal5 프로젝트 다이어리' 카테고리의 다른 글
  • Unreal - Behavior Tree(5) 스폰 / 디스폰
  • Unreal - Dissolve Material
  • Unreal - Behavior Tree(3) 플레이어와의 상호작용
  • Unreal - Behavior Tree(2) 플레이어 따라가기
lucodev
lucodev
커피와 노트북 그리고 개발
  • lucodev
    루코 개발테이블
    lucodev
  • 전체
    오늘
    어제
    • 분류 전체보기 (160)
      • Unreal5 프로젝트 다이어리 (73)
      • Unreal5 프로젝트 다이어리2 (10)
      • Unreal 팁 (8)
      • Unreal 디버깅 (8)
      • 코드 개인보관함 (8)
      • C++ 프로그래머스 다이어리 (47)
        • Stack,Queue (6)
        • Hash (4)
        • Heap (2)
        • Sort (5)
        • Exhaustive search (5)
        • Greedy (2)
        • BFS , DFS (6)
        • Graph (2)
        • Dynamic Programming (1)
        • C++ Math (2)
        • 기타 문제 (11)
      • 코딩테스트+@ (2)
      • 알고리즘 스타디 (1)
      • 알고리즘 스타디 과제 (3)
  • 인기 글

  • 최근 글

  • 최근 댓글

  • 링크

  • 공지사항

  • 블로그 메뉴

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

    언리얼 시퀀스
    언리얼 비헤이비어트리
    unreal look at
    unreal 컷씬
    언리얼 behavior tree
    언리얼 foot step
    언리얼 로딩창
    unreal 모션매칭
    언리얼 컷씬
    언리얼 모션매칭
    언리얼 motionmatching
    unreal loading
    언리얼 페이드 아웃
    언리얼 로딩
    언리얼 look at
    unreal 로딩
    언리얼
    unreal 시퀀스
    unreal sequence
    언리얼 behaviortree
  • hELLO· Designed By정상우.v4.10.3
lucodev
Unreal - Behavior Tree(4) AI Perception Team ID
상단으로

티스토리툴바