美文网首页
Unity 计算两个向量的夹角

Unity 计算两个向量的夹角

作者: 烂醉花间dlitf | 来源:发表于2021-04-18 18:35 被阅读0次

    计算两个向量夹角

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class AngleTest : MonoBehaviour
    {
        public GameObject move;
        public GameObject origin;
    
        private void OnDrawGizmos()
        {
            Vector3 originDirection = origin.transform.position - transform.position;
            Gizmos.DrawLine(transform.position, transform.position + originDirection);
            Vector3 nowDirection = move.transform.position - transform.position;
            Gizmos.DrawLine(transform.position, transform.position + nowDirection);
            float angle = Vector3.Angle(originDirection, nowDirection);
            float signedAngle = Vector3.SignedAngle(originDirection, nowDirection,Vector3.up);
            Debug.Log(angle.ToString()+" "+signedAngle.ToString());
        }
    }
    
    
    图示

    相关文章

      网友评论

          本文标题:Unity 计算两个向量的夹角

          本文链接:https://www.haomeiwen.com/subject/ggyvlltx.html