简单记录下点乘叉乘,要不每次用完就忘,忘了又查。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class TestCrossDot : MonoBehaviour
{/// <summary>/// 原点/// </summary>public Transform tfOrign;/// <summary>/// 物体1/// </summary>public Transform tf1;/// <summary>/// 物体2/// </summary>public Transform tf2;// Update is called once per framevoid Update(){Vector3 v3From = tf1.position - tfOrign.position;Vector3 v3To = tf2.position - tfOrign.position;//计算叉乘,y小于0在左,y大于0在右Vector3 cross = Vector3.Cross(v3From, v3To);//计算点乘,通向大于0,对向小于0float dot = Vector3.Dot(v3From, v3To);Debug.Log("cross=" + cross + " dot=" + dot);//计算两个向量夹角float angle = Vector3.Angle(v3From, v3To);//转换为0~360范围if (cross.y > 0){angle = 360 - angle;}Debug.Log("angle=" + angle);}}