zoukankan      html  css  js  c++  java
  • unity向量计算

    参考:https://www.cnblogs.com/wywnet/p/4790665.html

    上面的文章讲的很重要

    下面是我自己实现的一个例子

    一直一个向量,一个夹角,求另一个向量

    按P键改变夹角,Unity开启显示辅助线,可以看见

        public Transform Target;
        float jiaodu = 30f;
    
        void LateUpdate()
        {
            if (Input.GetKeyDown(KeyCode.P))
            {
                jiaodu += 10f;
            }
    
            Quaternion rotation = Quaternion.Euler(0f, jiaodu, 0f) * Target.rotation;
            Vector3 newPos = rotation * new Vector3(10f, 0f, 0f);
            Debug.DrawLine(Target.rotation * new Vector3(10f, 0f, 0f), Vector3.zero, Color.red);
            Debug.DrawLine(newPos, Vector3.zero, Color.red);
            Debug.Log("newpos " + newPos + " nowpos " + Target.position + " distance " + Vector3.Distance(newPos, Target.position));
        }

    向量旋转

    Quaternion.Euler (eulerAngles.x, eulerAngles.y, eulerAngles.z) * Vector3.forward
  • 相关阅读:
    iOS中图片与视频一次性多选
    UIImagePickerController Class
    1月16日
    10月20日
    1月14日
    1月13日
    1月12日
    1月11日
    课程评价与建议
    加分总结
  • 原文地址:https://www.cnblogs.com/sanyejun/p/7819335.html
Copyright © 2011-2022 走看看