先转下大佬的csdn
https://blog.youkuaiyun.com/qq_35539447/article/details/80486247?tdsourcetag=s_pctim_aiomsg
具体代码
public Vector3 pos0;
public Vector3 pos1;
public Vector3 pos2;
public float time = 3f;
public float startTime = 0;
Vector3 Bezier(Vector3 p0, Vector3 p1, Vector3 p2, float t)
{
Vector3 p0p1 = (1 - t) * p0 + t * p1;
Vector3 p1p2 = (1 - t) * p1 + t * p2;
Vector3 result = (1 - t) * p0p1 + t * p1p2;
return result;
}
void Start()
{
}
void Update()
{
if (Vector3.Distance(transform.position, pos2) <= 0.1f)
{
return;
}
startTime += Time.deltaTime;
if (startTime > time)
{
startTime = 0f;
}
Vector3 pos = Bezier(pos0, pos1, pos2, startTime / time);
transform.position = pos;
}
}