我正在构建一个简单的摄像机运动脚本,该脚本遵循贝塞尔曲线(使用线渲染器构建)。但是播放一段时间后,摄像机开始晃动片刻。
已经添加了带插值的刚体分量
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;
}
}
}
}
我希望我的相机一直遵循贝塞尔曲线,并从起点开始跟踪下一个。