Unity计算2个物体之间距离 (2个三维向量之间)
(图片来源网络,侵删)
public float GetDistance(Vector3 startPoint, Vector3 endPoint)
{
float distance = (startPoint - endPoint).magnitude;
return distance;
}
方法2
public double GetDistance(Vector3 startPoint, Vector3 endPoint)
{
double x = System.Math.Abs(endPoint.x - startPoint.x);
double y = System.Math.Abs(endPoint.y - startPoint.y);
return Math.Sqrt(x * x + y * y);
}
文章版权声明:除非注明,否则均为主机测评原创文章,转载或复制请以超链接形式并注明出处。