Physics
Physics sondea los contactos actuales de Collider y realiza raycasts sin asignación. Las callbacks del ciclo de vida de colisión y trigger proporcionan la ruta impulsada por eventos.
Consultas de contacto
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]) prueba cualquier contacto o un par específico. Physics.GetCollisionCount(gameObjectId) devuelve el recuento de contactos activos.
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
La dirección es normalizada por la ruta de consulta. layerMask y queryTriggers son opcionales. El método devuelve datos escalares del impacto en lugar de asignar una tabla de resultados.
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
El GameObject necesita el Collider apropiado. Las callbacks de trigger requieren Is Trigger; los contactos de bloqueo utilizan callbacks de colisión. Mantén las callbacks cortas y usa etiquetas o capas en lugar de comparar nombres repetidamente.