*interpolate (약어 lerp)
구현방법1. Approach 함수
Approach(G, C, dt)
if G - C > dt:
return C + dt
if G - C < -dt:
return C - dt
else:
return G
매 게임 프레임마다 Approach()의 결과값을 다시 Approach의 C값에 집어넣는다.
그러면 G에 dt씩 근접해간다. (dt를 더할 수도 뺄 수도 있다)
실제 사례에 적용 -
WASD로 이동할 때 그냥 바로 캐릭터의 velocity를 상수로 바꿔버리면 움직임이 부자연스럽다.
따라서 WASD를 눌렀을 때 VelocityGoal을 상수로 설정하고,
매 프레임(Update())마다 Approach(캐릭터.velocity, 캐릭터.velocityGoal, dt)를 실행하면
캐릭터가 자연스럽게 가/감속하는 것을 볼 수 있다.
dt를 높게 설정하면 마치 얼음에서 미끄러지는 듯한 효과를 연출할 수 있다.
'mathematics > game mathematics' 카테고리의 다른 글
[Mathematics] 4. Interpolation (0) | 2022.01.20 |
---|---|
[Mathematics] 3. 벡터의 외적 (0) | 2022.01.15 |
[Mathematics] 2. Euler angle (0) | 2022.01.15 |
[Mathematics] 1. Delta time (0) | 2022.01.15 |
오일러 각도 (Euler Angle) (0) | 2021.05.13 |