Quaternion.Slerp는 구면 선형 보간(Spherical Linear Interpolation)을 사용하여 두 쿼터니언 사이를 일정한 비율로 회전합니다. 회전의 진행률은 t 매개변수에 의해 결정됩니다. 이 메서드는 일정한 속도로 회전하는 느낌을 주며, 특히 큰 각도 차이를 부드럽게 회전할 때 유용합니다.
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, rotationSpeed * Time.deltaTime);
Quaternion.RotateTowards는 현재 회전에서 목표 회전까지 일정한 각도로 회전합니다. 이 메서드는 일정한 각도 속도로 회전하므로, 큰 각도 차이를 회전할 때 회전 속도가 느려지는 느낌이 들지 않습니다.
transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, rotationSpeed * Time.deltaTime);
@ 예시코드
using UnityEngine;
public class RotationExample : MonoBehaviour
{
public Transform target;
public float rotationSpeed = 90f; // 각도 속도 (degrees per second)
void Update()
{
if (target != null)
{
// 목표 회전 계산
Quaternion targetRotation = Quaternion.LookRotation(target.position - transform.position);
// Slerp 사용
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, rotationSpeed * Time.deltaTime);
// RotateTowards 사용
// transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, rotationSpeed * Time.deltaTime);
}
}
}
유니티 오브젝트 파괴, 분해, 자르기, 큐브 분해 폭발 (0) | 2024.07.29 |
---|---|
콜라이더 충돌 태그로 처리하기 (1) | 2024.07.24 |
유니티 캐릭터 컨트롤러 이동, 회전, 경사 오르기 (0) | 2024.07.24 |
유니티 모바일 최적화하기 (1) | 2024.07.23 |
유니티 Foot IK 적용하기 (0) | 2024.07.23 |