百花楼论坛全国_一品楼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);//新的方向相对旧的方向的偏转角度
        }
    }
    
    主站蜘蛛池模板: 靖江市| 雷波县| 龙井市| 宜君县| 丰镇市| 邹平县| 宜宾县| 涪陵区| 普兰店市| 马鞍山市| 瑞昌市| 静乐县| 马公市| 海原县| 垣曲县| 保山市| 武乡县| 如东县| 德庆县| 惠水县| 米林县| 且末县| 临泽县| 乐安县| 滨海县| 贵定县| 凉城县| 隆回县| 古交市| 浦江县| 衡南县| 富川| 商丘市| 安宁市| 彭州市| 康定县| 通山县| 修水县| 福贡县| 泰兴市| 黄平县|