Unity学习笔记–摄像机插值跟随
让摄像机跟随玩家运动,使用插值跟随可以让效果看起来更平滑,不那么死板`using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FellowCamera : MonoBehaviour {
private Transform targetPos;
private Vector3 offsetPos;//固定位置
private Vector3 temPos;//临时变量
// Use this for initialization
void Start () {
targetPos=GameObject.FindGameObjectWithTag(“Player”).transform;//注意要将要跟随的物体标签设置为“player”;
offsetPos = this.transform.position - targetPos.transform.position;
}
// Update is called once per frame
void FixedUpdate ()
{
temPos = targetPos.position + targetPos.TransformDirection(offsetPos);
this.transform.position = Vector3.Lerp(transform.position, temPos, Time.fixedDeltaTime*3);//插值跟随,fixedDeltaTime*3,"3"可以调节跟随的效果;
transform.LookAt(targetPos);
}
}
`