// _____ _____
// | | | |
// | x==|======|==x | 是错误的
// |_____| |_____|
//
// _____ _____
// | | | |
// | |x====x| | 正确的
// |_____| |_____|
//
//返回两个碰撞体之间最近的距离
public float Distance(Collider a, Collider b)
{
return Vector3.Distance(a.ClosestPointOnBounds(b.transform.position),
b.ClosestPointOnBounds(a.transform.position));
}
//返回碰撞器上最接近目标位置的一个点
public float Distance(Vector3 targetPos)
{
return Vector3.ClosestPoint(targetPos));
}
Unity 计算两个碰撞体之间的距离
最新推荐文章于 2024-06-06 11:43:25 发布