Unreal

[Unreal] 4월 10일 수업정리

k-codestudy 2025. 4. 10. 16:03

이동하는 발판 

interp to Movement와 spline을 이용하여 만들어 볼 예정이다.

Interp to Movement
Spline

 

우리가 이용해야 할 것은 Interp에 Control Points의 배열을 얻어오고 Spline의 Seleted Points를 배열에 넣어 움직이게 하는게 목표이다.

Interp의 Control Points
Spline의 Seleted Points
Control Points의 배열에 Spline의 Position을 넣는 과정

  1. Spline 컴포넌트에서 Spline Points의 개수를 가져와 For Loop( 반복문 )의 Last Index에 연결
    Get Number of Spline Points는 전체 개수를 반환하므로, For Loop의 Last Index에는 (개수 - 1)을 넣어줘야 한다
    예) 포인트가 6개라면 유효한 인덱스는 0~5이므로, Last Index는 5가 된다
  2. For Loop 내에서는 인덱스를 이용해 각 Spline Point의 위치를 얻고, Get Spline Point At → Break Spline Point 노드를 통해 Position 정보를 분리한다
  3. Position을 Interp to Movement의 Control Points 배열에 Set Array Elem으로 넣어준다

  1. Spline의 Spline Points 개수를 가져와 이 값을 Interp to Movement의 Control Points 배열의 Resize 노드에 연결하여,
    Control Points 배열의 크기를 Spline Points의 개수만큼으로 맞춰준다
  2. For Loop등을 통해 각 포인트의 위치를 해당 배열에 세팅하기 전에, 배열이 정확한 크기로 초기화되므로 Index 오류를 방지할 수 있다 (인덱스 초과 오류) 

  • 밖에서도 편집이 가능하게 Interp의 Duration, Behaviour Type을 디테일에서 편집가능하게 인스턴스 편집가능 설정

실행 결과

 

버튼을 만들어 On / Off 기능 추가

  1. BP_ThirdPerson에 이벤트 디스패처를 F키 누를시 호출되게 연결
  2. Btn에 BP_ThirdPerson을 캐스팅해서 바인드, 언바인드한 후 연결되어있는 이벤트에 Flip Flop으로 Interp to Movement의 움직이는 것을 Set Component Tick Enabled로 On / Off 설정

실행