SurvivalShooter学习笔记(一.相机跟随)

1.场景碰撞已好,地板需建一Quad去掉渲染留下碰撞,设置layer为Floor:用于建立摄像机朝向地面的射线,确定鼠标停留点,确定主角需要的朝向。

2.设置摄像机跟随主角: 本例中摄像机设置为正交模式。

摄像机跟随脚本:

public class CameraFollow : MonoBehaviour
    {
        public Transform target; //相机跟随的目标
        public float smoothing = 5f; //缓冲
        Vector3 offset; //存储主角与相机间的向量关系
        void Start ()
        {
            offset = transform.position - target.position;
        }
        void FixedUpdate ()
        {
            //相机运动目标位置
            Vector3 targetCamPos = target.position + offset;
            //相机运动
            transform.position = Vector3.Lerp (transform.position, targetCamPos, smoothing * Time.deltaTime);
        }
    }


原文地址:https://www.cnblogs.com/caymanlu/p/6361691.html