国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Unity使用圖片實現transform.LookAt功能

2019-11-09 15:50:54
字體:
來源:轉載
供稿:網友

效果如圖 使物體Y軸始終朝向目標物體 用于實現2D版子彈跟蹤功能 這里寫圖片描述

實現方法:

public Transform _collider_2; void Update() { transform.eulerAngles = LookTargetAngle(transform.position,_collider_2.position); } Vector3 LookTargetAngle(Vector3 playerPos, Vector3 targetPos) { float dx = targetPos.x - playerPos.x; float dy = targetPos.y - playerPos.y; float rotationZ = Mathf.Atan2(dy, dx) * 180 / Mathf.PI; //得到最終的角度并且確保在 [0, 360) 這個區間內 rotationZ -= 90; //獲取增加的角度 float originRotationZ = this.transform.eulerAngles.z; float addRotationZ = rotationZ - originRotationZ; //超過 180 度需要修改為負方向的角度 if (addRotationZ > 180) { addRotationZ -= 360; } //應用旋轉 return new Vector3(0, 0, this.transform.eulerAngles.z + addRotationZ); }

借鑒自: http://www.bubuko.com/infodetail-1243233.html


上一篇:transient

下一篇:Notification的基本使用

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 嘉祥县| 永城市| 宁都县| 滨州市| 万州区| 弋阳县| 五峰| 肇庆市| 清河县| 遂昌县| 延吉市| 贺州市| 临洮县| 时尚| 临夏市| 青冈县| 佛冈县| 淳安县| 南部县| 融水| 四会市| 洛扎县| 上饶县| 陵水| 南宫市| 惠水县| 商城县| 长阳| 舟曲县| 临夏市| 哈密市| 三明市| 余庆县| 两当县| 平度市| 大化| 日土县| 满城县| 长武县| 历史| 田阳县|