百花楼论坛全国_一品楼QM论坛_泻火吧论坛重庆

  • 您的位置:首页 > 新闻动态 > Unity3D

    unity3d角度偏移计算方法

    2019/4/9??????点击:
    using UnityEngine;
    using System.Collections;
     
    public class UserAnimatorMove : MonoBehaviour
    {
        private Vector3 oldVector3;
        private Vector3 newVector3;
        private Quaternion oldQuaternion;
        private Vector3 newRotatinForward;
        void Start()
        {
    
        }
        void Update()
        {
            if (Input.GetKeyDown(KeyCode.F1))
            {
     
                oldVector3 = this.transform.position;
                oldQuaternion = this.transform.rotation;
            }
            if (Input.GetKeyDown(KeyCode.F2))
            {
                StartCoroutine(MovePoint());
            }
        }
        private IEnumerator MovePoint()
        {
            //    oldVector3 = this.transform.position;
            //   oldQuaternion = this.transform.rotation;
            yield return new WaitForSeconds(0.2f);
            newVector3 = this.transform.position;
            newRotatinForward = this.transform.forward;
     
            float lenth = Vector3.Distance(oldVector3, newVector3);
            Vector3 velocity = Quaternion.Inverse(oldQuaternion) * newRotatinForward;
            float angle = Mathf.Atan2(velocity.x, velocity.z) * 180.0f / 3.14159f;
            Debug.Log(angle);//新的方向相对旧的方向的偏转角度
        }
    }
    
    主站蜘蛛池模板: 安国市| 广宗县| 句容市| 云梦县| 灵宝市| 昭平县| 江北区| 云林县| 高唐县| 分宜县| 禄丰县| 沧源| 新竹市| 驻马店市| 五寨县| 双江| 林甸县| 扶沟县| 清河县| 正宁县| 东乡| 东阳市| 镇赉县| 土默特右旗| 运城市| 迁西县| 耿马| 永仁县| 双辽市| 綦江县| 雷州市| 公主岭市| 罗平县| 深泽县| 镇赉县| 皋兰县| 桃江县| 宜兴市| 苗栗县| 玉林市| 米林县|