百花楼论坛全国_一品楼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);//新的方向相对旧的方向的偏转角度
        }
    }
    
    主站蜘蛛池模板: 漳浦县| 鸡泽县| 青河县| 额敏县| 惠东县| 南昌县| 体育| 十堰市| 吴忠市| 宜都市| 武陟县| 镇沅| 崇义县| 泽州县| 沅陵县| 甘肃省| 临邑县| 眉山市| 青川县| 盐池县| 巴中市| 萨嘎县| 同仁县| 拉孜县| 钦州市| 万安县| 砀山县| 长顺县| 龙井市| 陆良县| 汝城县| 大埔县| 吉林市| 兰西县| 泰顺县| 铅山县| 香港 | 永康市| 沂源县| 晋宁县| 岑巩县|