游戏引擎 c# VR 游戏开发 Unity计算2个物体之间距离 (2个三维向量之间) - return distance
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);
}
参考文章