如何解决“统一遵循贝塞尔曲线时不必要的相机抖动”?

时间:2019-04-03 19:40:35

标签: unity3d camera bezier shake

我正在构建一个简单的摄像机运动脚本,该脚本遵循贝塞尔曲线(使用线渲染器构建)。但是播放一段时间后,摄像机开始晃动片刻。

已经添加了带插值的刚体分量

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class QBCurveFollower : MonoBehaviour {

    public int totalPathsInCurrentWaypoints;
    public int nextTpicw;

    public LineRenderer ln;
    public LineRenderer nextLn;

    public int i = 0;
    public float step = 1f;
    public float speedMultiplier = 1f;

    public Transform finalPoint;
    public Transform nextFinalPoint;
    // Use this for initialization

    void Start () {
    }

    void FixedUpdate(){
        if ((i + 1) != totalPathsInCurrentWaypoints) {

            Vector3 target = ln.GetPosition (i);

            //for mission//
            if (roverCore.start) { 
                Missions.distance = Vector3.Distance(this.transform.position, ln.GetPosition(i));
                Missions.updateDistance = true;
            }

            if (roverCore.start) {
                GameController.distance += Vector3.Distance(this.transform.position, ln.GetPosition(i));
            }
            ///////////////

            for (int c = 0; c < speedMultiplier; c++) {
                transform.position = Vector3.MoveTowards (this.transform.position, target, step );
                if (target != null)
                {
                    transform.LookAt(target);

                }

                if (transform.position == target && i < 299)
                {
                    i++;
                    target = ln.GetPosition(i);

                    if (target != null)
                    {
                        transform.LookAt(target);

                    }
                }
            }
        }

        if ((i + 1) == totalPathsInCurrentWaypoints && nextLn != null)
        {
            if (i == 299)
            {
                ln = nextLn;
                totalPathsInCurrentWaypoints = nextTpicw;
                finalPoint = nextFinalPoint;
                nextFinalPoint = null;
                nextLn = null;
                nextTpicw = 0;
                i = 1;
                TileManager.corsRemove = true;
            }
        }
    }
}

我希望我的相机一直遵循贝塞尔曲线,并从起点开始跟踪下一个。

0 个答案:

没有答案