我让一个字符在圆的表面上移动。我让摄影机跟随角色移动和旋转。但是相机的移动和旋转非常不稳定。如果我增加第三个参数的值,震动就会增加。并且为了减小第三个参数的值,相机不旋转以保持角色。帮我修复
我的代码相机跟随播放器
public class CameraFollow : MonoBehaviour
{
public Transform player;
GameController gc;
public float speed = 2;
Vector3 pos = new Vector3 (0, 0, -10);
// Use this for initialization
void Start ()
{
gc = FindObjectOfType (typeof(GameController)) as GameController;
}
void FixedUpdate ()
{
if (gc.gameState == GameController.GameState.playing || gc.gameState == GameController.GameState.changeWave) {
transform.position = player.position + pos;
transform.rotation = Quaternion.Slerp (transform.rotation,
player.transform.rotation,
speed * Time.deltaTime);
}
}
}
在FixedUpdate
内部设置变换的位置无疑是一个危险信号,尤其是当您报告它"不稳定"时。与显示的帧相比,固定更新以不规则的间隔发生。这是因为物理学需要使用固定的时间步长进行更新。这种情况的原因超出了这个问题的范围。
长话短说,试着把FixedUpdate
改成Update
,这样就可以解决看起来"不稳定"的问题。
如果这不起作用,请告诉我,我会寻找其他可能的原因。
如果使用Rigidbody2D移动角色,请确保将其Interpolate属性设置为"Interpolate"。这应该可以修复它。