Skip to main content

Physics

Physics polls current Collider contacts and performs allocation-free raycasts. Collision and trigger lifecycle callbacks provide the event-driven path.

Contact Queries

if Physics.IsColliding(gameObjectId) then
local count = Physics.GetCollisionCount(gameObjectId)
end

if Physics.IsColliding(gameObjectId, doorGameObjectId) then
-- This exact pair currently overlaps.
end

Physics.IsColliding(gameObjectId[, otherGameObjectId]) tests any contact or a specific pair. Physics.GetCollisionCount(gameObjectId) returns the active contact count.

Raycast

local hit, hitGameObjectId,
hitX, hitY, hitZ,
normalX, normalY, normalZ,
distance = Physics.Raycast(
originX, originY, originZ,
directionX, directionY, directionZ,
2.5,
layerMask,
false
)

if hit and GameObject.CompareTag(hitGameObjectId, "Interactable") then
Log.Print("Target at " .. tostring(distance))
end

The direction is normalized by the query path. layerMask and queryTriggers are optional. The method returns scalar hit data rather than allocating a result table.

Callbacks

function OnCollisionEnter(gameObjectId, otherGameObjectId) end
function OnCollisionStay(gameObjectId, otherGameObjectId) end
function OnCollisionExit(gameObjectId, otherGameObjectId) end

function OnTriggerEnter(gameObjectId, otherGameObjectId) end
function OnTriggerStay(gameObjectId, otherGameObjectId) end
function OnTriggerExit(gameObjectId, otherGameObjectId) end

The GameObject needs the appropriate Collider. Trigger callbacks require Is Trigger; blocking contacts use collision callbacks. Keep callbacks short and use tags or layers instead of repeatedly comparing names.