Skip to content

Api > Physics > ComputePenetration()


Physics.ComputePenetration(Collider colliderA, Vector3 positionA, Quaternion rotationA, Collider colliderB, Vector3 positionB, Quaternion rotationB)⚓︎

Compute the minimal translation required to separate the given colliders apart at specified poses.

Parameters:⚓︎

Name Type Description
colliderA Collider The first collider.
positionA Vector3 Position of the first collider.
rotationA Quaternion Rotation of the first collider.
colliderB Collider The second collider.
positionB Vector3 Position of the second collider.
rotationB Quaternion Rotation of the second collider.

Returns:⚓︎

type Description
boolean True, if the colliders overlap at the given poses.
Vector3 Direction along which the translation required to separate the colliders apart is minimal.
number The distance along direction that is required to separate the colliders apart.

Usage⚓︎

---@type Collider
local colliderA;

---@type Vector3
local positionA;

---@type Quaternion
local rotationA;

---@type Collider
local colliderB;

---@type Vector3
local positionB;

---@type Quaternion
local rotationB;


local val0, val1, val2 = Physics:ComputePenetration(colliderA, positionA, rotationA, colliderB, positionB, rotationB)

Extra Detail⚓︎

Translating the first collider by direction * distance will separate the colliders apart if the function returned true. Otherwise, direction and distance are not defined.

One of the colliders has to be BoxCollider, SphereCollider CapsuleCollider or a convex MeshCollider. The other one can be any type.

Note that you aren't restricted to the position and rotation the colliders have at the moment of the call. Passing position or rotation that is different from the currently set one doesn't have an effect of physically moving any colliders thus has no side effects on the Scene.

Doesn't depend on any spatial structures to be updated first, so is not bound to be used only within FixedUpdate timeframe.