- 三次贝塞尔曲线
- 设置三个点的坐标,通过贝塞尔曲线运算,在 LineRender 中插入坐标,使其拟合;
主要方法如下:
void getBezier(int num)
{
line.positionCount = 0;
Vector3[] vector3 = new Vector3[num+1];
for (int i = 0; i <= num; i++)
{
float value = ((float)i / (float)num);
vector3[i]= (1 - value * value) * tag0.transform.position + 2 * value * (1 - value) * tag1.transform.position + value * value * tag2.transform.position;
//Debug.Log(vector3[i]+" "+ value.ToString("")+" "+ num+ " " + i);
}
line.positionCount = vector3.Length;
line.SetPositions(vector3);
for (int i = 0; i < vector3.Length; i++)
{
line.SetPosition(i, vector3[i]);
}
}