【发布时间】:2021-04-21 12:09:58
【问题描述】:
我最近在 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);
}
}
【问题讨论】:
-
我的第一反应是尝试在 FixedUpdate 而不是 Update 中移动您的相机。以下视频可能会帮助您更好地了解这些差异:youtube.com/watch?v=MfIsp28TYAQ
-
如果您还使用
Time.deltaTime作为插值因子怎么办?目前,您移动了每帧当前位置和目标位置之间距离的修复5%...也许宁可使用例如0.5f * Time.deltaTime?