一、2d贝塞尔曲线
1、方法:
/// <summary>
/// 贝塞尔曲线
/// </summary>
public static Vector3 Bezier3(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;
}
2、以特效飞行为例:
private IEnumerator EffectFly()
{
Vector3 start = ;//起始位置
Vector3 between = m_board.m_title.transform.position;//目标位置
Vector3 end = ;//目标位置
float totalTime = 1;//飞行时间
Gameobject fly = GameObject.Instantiate(obj, parent, null, start)//创建特效
float flyTime = 0f;
while (flyTime <= tTime)
{
flyTime += Time.deltaTime;
Vector3 pos = Global.Bezier3(start, between, end, flyTime / totalTime);
fly.transform.position = pos ;
yield return new WaitForSeconds(0.01f);
}
}
二、3d贝塞尔曲线
1、设置物体固定移动路线
可以使用Cinemachine,使用方法请查看https://blog.csdn.net/RocketJ/article/details/119907836
2、其他插件使用(例如LayaAir中的LayaBezierPath)