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

언리얼엔진5 c++ LineTrace

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

 

▣ LineTrace를 쏘는 함수에 코드를 완성합니다.

 

▣ 필요한 변수를 정의합니다. 각각 LineTrace() 함수안에 들어갈 매개변수입니다.

 

▣ DrawDebugLine() 함수는 LineTrace 라인을 그려주기 위함입니다. 

 

https://docs.unrealengine.com/4.27/en-US/API/Runtime/Engine/Engine/UWorld/LineTraceSingleByChannel/

 

UWorld::LineTraceSingleByChannel

Trace a ray against the world using a specific channel and return the first blocking hit

docs.unrealengine.com

 

https://docs.unrealengine.com/4.27/en-US/API/Runtime/Engine/DrawDebugLine/

 

DrawDebugLine

Draw a debug line

docs.unrealengine.com

 

 

▣ ECC_GameTraceChannel에 있는 건 우리가 생성한 Trace 채널을 의미합니다. 

 

 

▣ 프로젝트 파일에 DefaultEngine.ini 파일에서 검색하면 이렇게 GameTraceChannel이 어떤건지 확인할 수 있습니다. 

 

 

▣ 컴파일 후 플레이하고 키를 누르면 이렇게 Box가 충돌되어 삭제되는 걸 확인할 수 있습니다.

 

 

▣ 위에 코드 과정이 이미지처럼 블루프린트와 동일하다고 생각하시면 됩니다. 

 

 

▣ LineTraceMulti 같은 경우 여러 개를 받아오기 때문에 배열에 템플릿 형식으로 저장하고  for문을 사용합니다.

또한 Tag에 대한 조건을 확인하고 코드를 호출하게 코드를 완성할 수도 있습니다.

 

 

 

▣ 컴파일 후 조건이 맞는 엑터만 삭제됩니다. 

 

 

 

▣ #include "Kismet/KismetSystemLibrary.h" 헤더를 추가합니다. 

 

 

▣ 그리고 아까 코드를 삭제하고 UKismetSystemLibrary:: 접근하여 LineTraceSingle 함수를 호출하는 코드를 완성합니다. 

 

▣  GetWorld()에 접근한 LineTrace와 다르게  ETraceTypeQuery::TraceTypeQuery1 으로 Trace 채널을 접근합니다. 

TraceTypeQuery 1 == TraceChannel 0, TraceTypeQuery 2 == TraceChannel 1 , TraceTypeQuery 3 == TraceChannel 2 이런 식으로 접근한다고 생각하시면 되고 해당 함수 인수에 맞게 값을 넣어 코드를 완성합니다.

 

 

https://dev.epicgames.com/documentation/ko-kr/unreal-engine/API/Runtime/Engine/Kismet/UKismetSystemLibrary/LineTraceSingle?application_version=5.3

 

UKismetSystemLibrary::LineTraceSingle

Does a collision trace along the given line and returns the first blocking hit encountered.

dev.epicgames.com

 

 

▣ 조절하고 싶은 채널에 콜리전 상태도 지정하고 

 

 

▣ 컴파일 후 플레이해보면 콜리전 상태에 따라 그리고 채널에 따라 충돌이 되는 걸 확인할 수 있습니다. 

 

 

▣ USismetSystemLibrary를 접근하면 BoxTrace에 대한 함수도 사용합니다. 

아까와 다르게 Box에 크기 및 회전 값을 추가해야 합니다. 

 

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

 

UKismetSystemLibrary::BoxTraceSingle

Sweeps a box along the given line and returns the first blocking hit encountered.

dev.epicgames.com

 

 

▣ 저장 및 컴파일 후 플레이하면 Box를 확인할 수 있습니다. 

 

 

728x90
반응형

댓글