• 摄像机跟随物体,修复物体遮挡


    using System.Collections;
     
    public class CamFollowPlayer : MonoBehaviour {
     
     public float moveSpeed = 3;
     public float rotateSpeed = 3;
     
     private Vector3 offset;
     
     private Transform player;
     
     void Awake()
     {
      player = GameObject.FindGameObjectWithTag ("Player").transform;
      offset = transform.position - player.position;
      offset = new Vector3 (0, offset.y, offset.z);
     }
     
     // Update is called once per frame
     void Update ()
     {
      Vector3 beginPos = player.position + offset;
      Vector3 endPos = player.position + offset.magnitude * Vector3.up;
     
      Vector3 pos1 = Vector3.Lerp (beginPos, endPos, 0.25f);
      Vector3 pos2 = Vector3.Lerp (beginPos, endPos, 0.5f);
      Vector3 pos3 = Vector3.Lerp (beginPos, endPos, 0.75f);
     
      Vector3[] posArray = new Vector3[]{beginPos, pos1, pos2, pos3, endPos};
      Vector3 targetPos = posArray [0];
     
      for (int i = 0; i < 5; i++)
      {
       RaycastHit hitInfo;  //存储射线碰撞检测信息
     
       if(Physics.Raycast(posArray[i], player.position - posArray[i], out hitInfo)) //起始位置 ,方向 ,输出信息 返回是否有射线打到位置
       {
        if(hitInfo.collider.tag != "Player")
        {
         continue;
        }
        else
        {
         targetPos = posArray[i];
         break;
        }
       }
       else
       {
        targetPos = posArray[0];
        break;
       }
      }
      this.transform.position = Vector3.Lerp(transform.position, targetPos, Time.deltaTime * moveSpeed);
      Quaternion nowRotation = transform.rotation;
     
      transform.LookAt (player.position);
      transform.rotation = Quaternion.Lerp (nowRotation, transform.rotation, Time.deltaTime * rotateSpeed);
     }
    }
  • 相关阅读:
    CF1008D Pave the Parallelepiped
    Luogu P3324 [SDOI2015]星际战争
    Luogu P3157 [CQOI2011]动态逆序对
    CF1295E Permutation Separation
    位元算
    JavaScript 寻找数组中的第N大的元素
    JS常见的数组排序算法
    最新面试总结
    JavaScript BOM浏览器对象模型
    JavaScript DOM 事件
  • 原文地址:https://www.cnblogs.com/JimmyCode/p/4810728.html
Copyright © 2020-2023  润新知