Version: 2020.1

Physics.CheckCapsule

切换到手册
public static bool CheckCapsule (Vector3 start, Vector3 end, float radius, int layerMask= DefaultRaycastLayers, QueryTriggerInteraction queryTriggerInteraction= QueryTriggerInteraction.UseGlobal);

参数

start 胶囊体在 start 处的球体中心。
end 胶囊体在 end 处的球体中心。
radius 胶囊体的半径。
layermask 层遮罩,用于在投射胶囊体时有选择地忽略碰撞体。
queryTriggerInteraction 指定该查询是否应该命中触发器。

描述

检查是否有任何碰撞体与世界空间中的胶囊形体积重叠。

胶囊体由中心位于 point1radius、半径为 radius 的两个球体界定,两个球体构成胶囊体的两个末端。

using UnityEngine;

public class Example : MonoBehaviour { // Given the start and end waypoints of a corridor, check if there is enough // room for an object of a certain width to pass through. bool CorridorIsWideEnough(Vector3 startPt, Vector3 endPt, float width) { return Physics.CheckCapsule(startPt, endPt, width); } }