【发布时间】:2016-02-03 03:40:35
【问题描述】:
我的相机跟随脚本不是很流畅。如何平滑相机的运动?
这里是:
using UnityEngine;
using System.Collections;
public class FollowCamera : MonoBehaviour {
public float interpVelocity;
public float minDistance;
public float followDistance;
public GameObject target;
public Vector3 offset;
Vector3 targetPos;
void Start () {
targetPos = transform.position;
}
void FixedUpdate () {
if (target)
{
Vector3 posNoZ = transform.position;
posNoZ.z = target.transform.position.z;
Vector3 targetDirection = (target.transform.position - posNoZ);
interpVelocity = targetDirection.magnitude * 5f;
targetPos = transform.position + (targetDirection.normalized * interpVelocity * Time.deltaTime);
transform.position = Vector3.Lerp( transform.position, targetPos + offset, 0.25f);
}
}
}
该脚本使相机跟随一个旋转目标。
【问题讨论】:
-
将其从 FixedUpdate 移至 LateUpdate。 FixedUpdate 的调用频率通常比 Update 少,Camera 移动最好在 LateUpdate 上。
-
还阅读了这个问题的数千个完全相同的重复项stackoverflow.com/questions/26640891/…
标签: c# unity3d unity5 gameobject