摄像机摇移跟随

来源:互联网 发布:tensorflow tutorial 编辑:程序博客网 时间:2024/05/17 07:50
    public float distanceAway;          // distance from the back of the craft    public float distanceUp;            // distance above the craft    public float smooth;                // how smooth the camera movement is    GameObject hovercraft;      // to store the hovercraft    Vector3 targetPosition;     // the position the camera is trying to be in    Transform follow;    void Start ()    {        follow = GameObject.FindWithTag ("Player").transform;    }    void LateUpdate ()    {        // setting the target position to be the correct offset from the hovercraft        targetPosition = follow.position + Vector3.up * distanceUp + follow.forward * distanceAway;        // making a smooth transition between it's current position and the position it wants to be in        transform.position = Vector3.Lerp (transform.position, targetPosition, Time.deltaTime * smooth);        // make sure the camera is looking the right way!        transform.LookAt (follow);    }
    Vector3 offset;    Transform  fly;    // Use this for initialization    void Start () {        fly = GameObject .FindGameObjectWithTag ("Player").transform ;        offset = fly  .position - transform .position;    }    // Update is called once per frame    void Update () {        transform .position = new Vector3 (fly .position .x -offset .x ,transform .position.y ,fly .position .z -offset .z) ;    }
0 0
原创粉丝点击