C#/Unity Time.deltaTime 使 lerping Camera Follow 跳转

问题描述

我最近在 Unity 制作的 2D 游戏中发布了一个抖动相机跟随的问题,该问题已解决 here

但是过了一段时间我注意到,我仍然在跳跃。我现在知道,问题在于我的相机跟随的 lerp 方法。 Time.deltaTime 如我之前的问题所述而变化,因此使玩家每帧移动不同的距离。但是由于相机的反应有延迟,您可以在屏幕上看到跳跃(在设备上甚至比在 Unity 编辑器中更多)。

一个解决方案是检测那些 Time.DeltaTime 跳跃,在这些情况下让相机以某种方式模仿那个跳跃,我说得对吗?这里有什么解决方法?

这些是我的脚本:

public class Player: MonoBehaviour 
{ 
    float speed = 5f; 
    void Update() 
    { 
        transform.Translate(0,speed*Time.deltaTime,0); 
    } 
} 

public class CamFollow : MonoBehaviour 
{ 
    public Transform Player; 
    private Vector3 FollowVector; 
    float transition = 0.05f;
    void LateUpdate() 
    { 
        FollowVector = Player.position - new Vector3(0,-4.0f,10); 
        transform.position = Vector3.Lerp(transform.position,FollowVector,transition); 
    } 
} 

解决方法

尝试使用 Time.fixedDeltaTime。这就像 deltatime 但它是固定的,所以它不像你说的那样。它确实减少了抖动,但我建议使用 Cinemachine,因为它的性能非常好,而且您可以对其进行很多控制。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...