Unity中使用SimpleWaypointSystem控制物体移动

在Unity中通过SimpleWaypointSystem在沙盘上绘制出轨迹,一个物体沿着轨迹移动。
需要实现当沙盘旋转时,物体、轨迹也跟随旋转,且物体的移动不会偏移轨迹。

重要变量:fullPosition【获取和设置补间的时间位置(包括循环,排除延迟)】
通过fullPosition的值可以动态记录物体在轨迹上的位置点,然后将记录的值重新赋值给旋转沙盘后重绘轨迹上相同的位置点。

  /// <summary>
    /// 记录小车在轨迹上的位置点
    /// </summary>
    float pathPos;
    /// <summary>
    /// 设置小车的位置和移动轨迹
    /// </summary>
    private void SetCarPosAndPath()
    {
    	//暂停当前正在执行的动画
        SandCarManager_01.GetInstance().sandCar.GetComponent<splineMove>().Pause();
        //记录当前小车在轨迹上的位置点
        pathPos = SandCarManager_01.GetInstance().sandCar.GetComponent<splineMove>().tween.fullPosition;
        SandCarManager_01.GetInstance().sandCar.GetComponent<splineMove>().reverse = false;
        StartCoroutine(RedrawPath());
    }

    IEnumerator RedrawPath()
    {
        yield return new WaitForSeconds(0.5f);//延迟调用StartMove函数+重绘路径
        SandCarManager_01.GetInstance().sandCar.GetComponent<splineMove>().StartMove();
        yield return new WaitForSeconds(0.05f);//延迟将小车轨迹上的位置点赋值给新轨迹对应的位置点
        SandCarManager_01.GetInstance().sandCar.GetComponent<splineMove>().tween.fullPosition = pathPos;

    }
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值