두 선형 벡터(from, to) 사이의 시간에 따른 위치를 구할 때 사용됩니다. 라고 나와 있는데
transform.position = Vector3.Lerp(시작위치, 끝위치, 시간); 요론 구조로 되어있다.
이걸 선형 보간이라는 방법을 사용하는데 쉽게 풀어서 설명하면
시작점과 끝점 사이에 있는 점들에 대해서 시간의 변화에 따라서 해당 점들을 예측하는 것을 말한다.
이 시간값을 이용해서 점점 느려지게 할수도 있고 일정하게 가도록 할수도 있다.
1
2
3
4
5
6
|
void Update(){
transform.position = Vector3.Lerp(transform.position,
destination.position,
speed * Time.deltaTime);
}
| cs |
위치가 계속 바뀔지언정 목적지에는 도달할수가 없다.
이게 유용한 이유는 물체의 위치를 이동하는데 쓸수도있지만 color, rotation값등등 다양한 곳에 쓸수가 있다.
1
2
3
4
5
6
7
8
9
|
void Update (){
spriteRenderer.color = Color.Lerp(spriteRenderer.color,
destinationColor,
speed * Time.deltaTime);
transform.rotation = Quaternion.Lerp(transform.rotation,
destinationRotation,
speed * Time.deltaTime);
}
| cs |
댓글 없음:
댓글 쓰기