본문 바로가기
[ CODING STUDY ]/》언리얼엔진5 실습

언리얼엔진5 c++ AIController(Focus, Move)

by MRG 2024. 4. 27.
728x90
반응형

 

▣ 먼저 AiController c++ 코드를 생성합니다. 

 

 

▣ 그리고 생성한 c++ AiController를 상속한 블루프린트도 생성합니다. 

 

 

▣ 적 블루프린트에 들어가서 디테일탭에 Ai Controller Class를 아까 생성한 AiController 블루프린트로 지정합니다. 

 

 

▣ AiController c++ 코드에. h 헤더파일로 들어가서 BeginPlay(), Tick() 함수를 선언하고 함수 정의까지 진행합니다. 

 

 

▣. cpp 파일로 가서 #include "Kismet/GameplayStatics.h"를 선언합니다. 

그리고 Tick() 함수에 플레이어 Pawn을 저장하는 코드, Ai 시선처리하는 함수, Ai 이동하는 함수 코드를 완성합니다. 

 

▣ UGameplayStatics::GetPlayerPawn() : 지정된 플레이어 인덱스에 있는 플레이어 컨트롤러의 폰을 반환합니다.

 

▣ AAIController::MoveToActor : AI가 지정된 목표 액터를 향해 이동하도록 만들고(대상은 지속적으로 업데이트됩니다), 따라가는 모든 활성 경로를 중단합니다.

 

▣ MoveToActor() 함수에 AcceptanceRadius는 이동반경을 의미합니다.

 

https://dev.epicgames.com/documentation/en-us/unreal-engine/API/Runtime/Engine/Kismet/UGameplayStatics/GetPlayerPawn?application_version=5.3

 

UGameplayStatics::GetPlayerPawn

Returns the pawn for the player controller at the specified player index.

dev.epicgames.com

 

 

 

https://dev.epicgames.com/documentation/en-us/unreal-engine/API/Runtime/AIModule/AAIController/SetFocus?application_version=5.3

 

AAIController::SetFocus

Set Focus actor for given priority, will set FocalPoint as a result.

dev.epicgames.com

 

 

https://dev.epicgames.com/documentation/en-us/unreal-engine/API/Runtime/AIModule/AAIController/MoveToActor?application_version=5.3

 

AAIController::MoveToActor

Makes AI go toward specified Goal actor (destination will be continuously updated), aborts any active path following

dev.epicgames.com

 

 

▣ 저장 및 컴파일 후 플레이를 해보면 AI가 플레이를 보면서 따라오는 걸 확인할 수 있습니다.

 

 

▣ 이동속도는 Character Movement에서 조절하면 됩니다.

728x90
반응형

댓글