1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關(guān)咨詢
      選擇下列產(chǎn)品馬上在線溝通
      服務(wù)時間:8:30-17:00
      你可能遇到了下面的問題
      關(guān)閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
      Unity實現(xiàn)已知落點和速度自動計算發(fā)射角度

      本文實例為大家分享了Unity已知落點和速度自動計算發(fā)射角度的具體代碼,供大家參考,具體內(nèi)容如下

      創(chuàng)新互聯(lián)是一家專注于做網(wǎng)站、成都網(wǎng)站建設(shè)與策劃設(shè)計,馬村網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設(shè)10余年,網(wǎng)設(shè)計領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:馬村等地區(qū)。馬村做網(wǎng)站價格咨詢:028-86922220

      在發(fā)射物已知落點和速度的情況下如果剛體應(yīng)用重力,不容易算出發(fā)射角度,以下為計算過程

      /// 
      /// 掛載到發(fā)射器上即可
      /// 
      public class Rotate : MonoBehaviour
      {
       public GameObject prefab; //發(fā)射物
       public float speed;   //發(fā)射物速度
       public bool 拋射 = false; //拋射:仰角 > 45°,否:仰角 < 45°
       Ray RayMouse;
       Vector3 direction;
       Quaternion rotation;
       
       void Update()
       {
        if (Input.GetMouseButtonDown(0))
        {
         GameObject go = Instantiate(prefab, transform.position, transform.rotation);
         go.AddComponent().velocity = go.transform.forward * speed;
        }
      
        RaycastHit hit;
        RayMouse = Camera.main.ScreenPointToRay(Input.mousePosition);
        if (Physics.Raycast(RayMouse.origin, RayMouse.direction, out hit, Mathf.Infinity))
        {
         RotateToMouseDirection(gameObject, hit.point);
        }
       }
      
       /// 
       /// 執(zhí)行整體旋轉(zhuǎn)
       /// 
       /// 旋轉(zhuǎn)的物體(自身)
       /// 目標(biāo)點(鼠標(biāo)指向)
       void RotateToMouseDirection(GameObject obj, Vector3 destination)
       {
        direction = destination - obj.transform.position;
        rotation = Quaternion.LookRotation(direction);
      
        Vector3 finalAngle = rotation.eulerAngles;
        float targetAng = Angle(destination);
        finalAngle = new Vector3(-targetAng, finalAngle.y, finalAngle.z);//注意正負(fù)
      
        obj.transform.localRotation = Quaternion.Euler(finalAngle);
       }
      
       /// 
       /// 自動計算x歐拉角,即仰角
       /// 
       /// 目標(biāo)點坐標(biāo)
       /// 
       float Angle(Vector3 target)
       {
        float angleX;
        float distX = Vector2.Distance(new Vector2(target.x, target.z), new Vector2(transform.position.x, transform.position.z));
        float distY = target.y - transform.position.y;
        float posBase = (Physics.gravity.y * Mathf.Pow(distX, 2.0f)) / (2.0f * Mathf.Pow(speed, 2.0f));
        float posX = distX / posBase;
        float posY = (Mathf.Pow(posX, 2.0f) / 4.0f) - ((posBase - distY) / posBase);
        if (posY >= 0.0f)
        {
         if (拋射) //字段
          angleX = Mathf.Rad2Deg * Mathf.Atan(-posX / 2.0f + Mathf.Pow(posY, 0.5f));
         else
          angleX = Mathf.Rad2Deg * Mathf.Atan(-posX / 2.0f - Mathf.Pow(posY, 0.5f));
        }
        else
        {
         angleX = 45.0f;
        }
        return angleX;
       }
      }

      實際效果

      Unity實現(xiàn)已知落點和速度自動計算發(fā)射角度

      拋射效果

      Unity實現(xiàn)已知落點和速度自動計算發(fā)射角度

      以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。


      網(wǎng)站標(biāo)題:Unity實現(xiàn)已知落點和速度自動計算發(fā)射角度
      本文路徑:http://www.ef60e0e.cn/article/pdsshd.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        陵川县| 恩平市| 天峻县| 襄城县| 锡林郭勒盟| 海原县| 泉州市| 辰溪县| 建平县| 灌阳县| 贵溪市| 安丘市| 万源市| 武川县| 桑日县| 包头市| 泸州市| 上蔡县| 静海县| 海晏县| 洛扎县| 郓城县| 娄底市| 呼玛县| 永定县| 伊吾县| 长寿区| 宣恩县| 玉环县| 高雄市| 高清| 什邡市| 南漳县| 寿光市| 射洪县| 铜陵市| 枣阳市| 观塘区| 吴堡县| 八宿县| 晴隆县|