Unity

Unity - 목적지로 위치 이동

U333 2021. 4. 2. 09:41

Unity - 목적지로 위치 이동

MoveTowards, Lerp, Slerp, SmoothDamp,

 

MoveTowards

지정된 목적지 좌표로 속도 만큼 이동하는 함수.
transform.position = Vector3.MoveTowards(transform.position, goalpos, speed);

 

Lerp

시작(rate=0)과 끝(rate=1)의 사이에서 가중치에 해당하는 위치를 얻는 함수.
transform.position = Vector3.Lerp(transform.position, goalpos, rate);

 

Slerp

곡선이동. 시작(rate=0)과 끝(rate=1)사이를 지정해 위치 얻음.
transform.position = Vector3.Slerp(gameObject.transform.position, goalpos, rate);

 

SmoothDamp

서서히 감속
Vector3 mVel = Vector3.zero;
//...
transform.position = Vector3.SmoothDamp(transform.position, goalpos, ref mVel, 1f);