Untiy 贝塞尔曲线

一、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)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值