unity 计算两点的的角度
float angle_360(Vector3 from_, Vector3 to_)
{
//两点的x、y值
float x = from_.x - to_.x;
float y = from_.y - to_.y;
//斜边长度
float hypotenuse = Mathf.Sqrt(Mathf.Pow(x,2f)+Mathf.Pow(y,2f));
//求出弧度
float cos = x / hypotenuse;
float radian = Mathf.Acos(cos);
//用弧度算出角度
float angle = 180 / (Mathf.PI / radian);
if (y < 0)
{
angle = -angle;
}
else if ((y == 0) && (x < 0))
{
angle = 180;
}
return angle;
}
Vector3 targetDir = targetPos.position - transform.position; // 目标坐标与当前坐标差的向量
Vector3.Angle(transform.forward,targetDir) // 返回当前坐标与目标坐标的角度