Unity/초보자가 알면 좋을 팁

Unity Lerp vs Slerp 단순 이해 (예제 코드 포함)

추운날_너를_기다리며 2026. 3. 26. 18:10

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