我正在开发一款 3D 横向卷轴游戏,其中我的相机使用 Vector3.lerp
跟随我的角色。
目前我的相机从侧面看着玩家,但在某些时候我希望相机过渡到 TopView(从顶部看角色),同时与角色保持一定的高度。
我通过创建名为 SideView 和 TopView 的相机设置来完成此操作。现在的问题是相机确实从 SideView 过渡到 TopView,但在过渡过程中,相机在 lerp
结束时抖动(当相机几乎位于目标位置时)。
如何使这种平滑(停止相机抖动)?
注意:相机和角色都在移动。
我的相机的源代码如下:
void LateUpdate ()
{
if(currentCameraSettings != null && target.transform != null)
{
targetPos = SetCameraTargetPos(target.transform);
if(duration != 0)
{
transform.position = Vector3.Lerp(transform.position,targetPos,(Time.time - startTime ) / duration );
}
else
{
transform.position = targetPos;
}
SetCameraRotation();
}
}
SetCameraTargetPos
在添加到目标角色的高度和 z 轴距离后返回目标位置。
最佳答案
听起来您的 Lerp
情况不对。我想你想在这里使用的是 MoveTowards
。
float step = speed * Time.deltaTime;
transform.position = Vector3.MoveTowards(transform.position, target.position, step);
如果您仍然“参差不齐”,请尝试使用 Time.smoothDeltaTime
。
关于c# - 跟随游戏对象并同时更改相机 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31913442/