- 선형보간법이란?
: 끝점의 값이 주어졌을 때 그 사이에 위치한 값을 추정하기 위하여 직선 거리에 따라 선형적으로 계산하는 방법
- C#에 선형보간을 적용하자!
// p1,p2를 d1:d2로 분할하는 p를 리턴한다. (단, d1+d2=1)
float lerp(float p1, float p2, float d1) {
return (1-d1)*p1 + d1*p2;
}
:두 좌표를 알면 일차함수식 적용 가능
- 코드 응용(좌우로 무한 반복)
float lerp_time = 0;
public float radian = 0;
public Transform start;
public Transform end;
public float x_offset = 0;
Vector3 destany = new Vector3();
public float Speed = 0.02f;
//float lerp_time2 = 0.0f;
//bool isAdd = true;
void Update()
{
// trasform.x 0~200~0~200
lerp_time = (Mathf.Sin(radian)+1)/2; //-1~0~1~0~-1 (+1)(*100) +1/2
//lerp_time = lerp_time2;
destany = Vector3.Lerp(start.position, end.position, lerp_time);
destany.x += x_offset;
transform.position = destany;
radian += Speed;
/*
if(isAdd == true)
{
lerp_time2 += 0.005f;
}
else
{
lerp_time2 -= 0.005f;
}
if(lerp_time2 < 0) { isAdd = true; OVRInput.SetControllerVibration(1, 1, OVRInput.Controller.RTouch); }
if(lerp_time2 > 1) { isAdd = false; OVRInput.SetControllerVibration(1, 1, OVRInput.Controller.RTouch); }
*/
}
'Unity Script(공통)' 카테고리의 다른 글
Unity SceneChanger + VR Fade In/Out(C#스크립트) (0) | 2022.09.16 |
---|---|
Unity Senario Manager(C#스크립트) (0) | 2022.09.16 |