Unreal - Behavior Tree(4) AI Perception Team ID

2025. 5. 4. 20:26·Unreal 프로젝트 다이어리/첫번째 프로젝트

현재 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이 적과 아군 중립을 구분을 하게됩니다

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

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
'Unreal 프로젝트 다이어리/첫번째 프로젝트' 카테고리의 다른 글
  • Unreal - Behavior Tree(5) 스폰 / 디스폰
  • Unreal - Dissolve Material
  • Unreal - Behavior Tree(3) 플레이어와의 상호작용
  • Unreal - Behavior Tree(2) 플레이어 따라가기
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)
  • 인기 글

  • 최근 글

  • 최근 댓글

  • 링크

  • 공지사항

  • 블로그 메뉴

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

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

티스토리툴바