1. Lerp (선형 보간) — 위치 이동
👉 두 지점 사이를 직선으로 이동
using UnityEngine;
public class LerpMoveExample : MonoBehaviour
{
public Transform startPoint;
public Transform endPoint;
[Range(0, 1)]
public float t;
private void Update()
{
transform.position = Vector3.Lerp(startPoint.position, endPoint.position, t);
}
}
💡 설명
- t = 0 → 시작 위치
- t = 1 → 도착 위치
- t = 0.5 → 중간 위치
👉 즉,
A → B를 직선으로 부드럽게 이동,
t는 “얼마나 이동했는지 비율(0~1)”이다.
🎮 실무 사용 예
- 카메라 따라가기
- UI 이동 애니메이션
- 캐릭터 위치 보간
2. Slerp (구면 보간) — 방향/회전
👉 곡선(원형 경로)으로 이동 / 회전 보간
using UnityEngine;
public class SlerpMoveExample : MonoBehaviour
{
public Transform startPoint;
public Transform endPoint;
[Range(0, 1)]
public float t;
private void Update()
{
transform.position = Vector3.Slerp(startPoint.position, endPoint.position, t);
}
}
💡 설명
- Lerp → 직선 이동
- Slerp → 곡선 이동 (원형 경로)
👉 중심을 기준으로 “빙 돌아가는 느낌”
3. 회전에서의 Slerp (핵심 사용처)
👉 Slerp는 사실 회전에서 진짜 많이 씀
using UnityEngine;
public class SlerpRotationExample : MonoBehaviour
{
public Transform target;
public float speed = 5f;
private void Update()
{
Vector3 direction = target.position - transform.position;
Quaternion targetRotation = Quaternion.LookRotation(direction);
transform.rotation = Quaternion.Slerp(
transform.rotation,
targetRotation,
Time.deltaTime * speed
);
}
}
💡 설명
👉 캐릭터가 타겟을 부드럽게 바라봄
- 순간 회전 ❌
- 자연스럽게 회전 ✅
🎯 4. Lerp vs Slerp 한눈에 비교
| 구분 | Lerp | Slerp |
| 이동 방식 | 직선 | 곡선 |
| 주 사용 | 위치 이동 | 회전 |
| 대표 예 | 카메라 추적 | 방향 전환 |
❗ 실수 포인트 (중요)
// ❌ 잘못된 사용
Vector3.Slerp(positionA, positionB, t);
👉 위치 이동에 쓰면
👉 빙 돌아서 이동하는 이상한 움직임 발생
핵심 정리
👉 Lerp는 직선 이동, Slerp는 회전과 방향 보간에 사용된다
특히:
- 카메라 이동 → Lerp
- 캐릭터 방향 회전 → Slerp
'Unity > 초보자가 알면 좋을 팁' 카테고리의 다른 글
| Unity 폰트 한글 적용 방법 (깨짐 없이 사용하는 법) (0) | 2026.03.26 |
|---|---|
| Unity UI 기초: Canvas 설정과 Expand 쉽게 이해하기 (0) | 2026.03.26 |
| Unity Lerp vs Slerp 차이 한 번에 이해하기! (0) | 2026.03.26 |
| Unity에서 캐릭터 이동 방식 종류에 대하여 (0) | 2026.03.03 |
| LateUpdate에 캐릭터 이동을 넣지 않는 이유에 대하여 (0) | 2026.03.03 |