offset 偏移
很巧妙的算法,
求得摄像机 和 主角的 偏移。
就可以根据这个等式 摄像机位置 = 主角+ 偏移
来实现摄像机跟随。
private void Start() {
player = GameObject.FindGameObjectWithTag("Player");
offset = this.transform.position - this.player.transform.position;
}
private void Update() {
if (this.player.transform.position.y + offset.y > this.transform.position.y)
this.transform.position = this.player.transform.position + this.offset;
}
错误方法:
吧人物移动距离 求得偏移向量直接 作用在摄像机上。emm 很难做到 摄像机的距离 和 人保持不变。久而久之就会导致 摄像机和人的 相对距离差距越来越大。