[英]Jittery camera movement in Unity 3D
我正在制作一個無盡的跑步游戲,比如寺廟跑。 相機在偏移處跟隨玩家。 當相機離玩家太近時,抖動變得非常明顯。 我認為當相機遠離玩家時(在游戲開始時,尚未達到偏移量時),它仍然很緊張。
如何解決抖動?
攝像頭代碼:
private void Start()
{
tempPos = target.position;
offset = transform.position - target.position;
}
// Update is called once per frame
void LateUpdate()
{
Vector3 followPos = target.position - target.forward * trailDistance;
followPos.y += heightOffset;
tempPos += (followPos - transform.position) * cameraDelay;
//var targetRotation = Quaternion.LookRotation(target.transform.position - transform.position);
//transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, turnSpeed * Time.deltaTime);
Vector3 smoothedPosition = Vector3.SmoothDamp(transform.position, tempPos, ref velocity, smoothSpeed);
transform.position = smoothedPosition;
transform.LookAt(target.transform);
}
我使用了一種更簡單的方法來做到這一點。 它還具有令人敬畏的平滑/延遲效果。 這也是您在多人游戲場景中使用的,當代碼由於延遲而非常緊張時。
float delay = 2f;// Play around with me
void FixedUpdate()
{
Vector3 followPos = target.position - target.forward * trailDistance;
transform.position = Vector3.Lerp(transform.position, followPos, delay);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.