Q.Slerp가 뭐야?
A.
Slerp는 구면선형보간(Spherically interpolate)을 의미한다.
구면선형보간은 두 지점 사이의 위치를 파악하는 선형보간(lerp)와 같지만 직선이 아닌 곡선으로 파악을한다.
Q.Slerp가 무슨뜻인지 알겠어, 그럼 Unity에서 어떡해 써??
A.
time 내에서 0 ~ 1 로 분할한뒤 위치를 적용시켜준다.
Vector3 start;
Vector3 end;
float time;
transform.position = Vector3.Lerp(start,end,time); // 선형 보간
transform.position = Vector3.SLerp(start,end,time); // 선형 보간
Lerp 레퍼런스
https://docs.unity3d.com/ScriptReference/Vector3.Lerp.html
Unity - Scripting API: Vector3.Lerp
Interpolates between the points a and b by the interpolant t. The parameter t is clamped to the range [0, 1]. This is most commonly used to find a point some fraction of the way along a line between two endpoints (e.g. to move an object gradually between t
docs.unity3d.com
Slerp 레퍼런스
https://docs.unity3d.com/ScriptReference/Vector3.Slerp.html
Unity - Scripting API: Vector3.Slerp
Interpolates between a and b by amount t. The difference between this and linear interpolation (aka, "lerp") is that the vectors are treated as directions rather than points in space. The direction of the returned vector is interpolated by the angle and it
docs.unity3d.com
Q.Slerp를 이용해서 Unity2D 객체 회전시키기
A.회전을 바로 하는게 아닌 구면 보간을 이용하여 자연스러운 회전을 만들고싶을때 사용된다.
왼쪽이 3D 월드 좌표축 , 오른쪽이 2D월드 좌표축이다.
즉, 유니티 2D에서 회전을 적용시키고 싶으면 x 축이 아닌 z축을 회전 시켜야되는것이다.
private void Rotate(float inputX)
{
//AngleAxis() : axis를 중심으로 angle(inputX)만큼 회전시킨 쿼터니언을 반환한다.
Quaternion Rot = Quaternion.AngleAxis((inputX), Vector3.forward);
transform.rotation = Quaternion.Slerp(transform.rotation, Rot, ROTATIONSPEED);
}
'Unity > Unity2D' 카테고리의 다른 글
Unity2D :: 타일맵을 이용한 오브젝트 꾸미기 (0) | 2024.10.07 |
---|