计算两个向量夹角
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());
}
}

图示
网友评论