GetEntityCollisions

From OxeyeWiki

Jump to: navigation, search

physics:getEntityCollisions(entityId)

Fetches a list of current collision points for a given entity. This list will not include sensor points, they are stored in a separate list and are fetched with getEntitySensorPoints.

Parameter Expected Type Description
enitityId An integer The entity's body identifier.
Returns

Returns a table containing collision elements (see below). If no collisions are found, this method returns nil to save some garbage collection performance. In other words, the returned table is never empty, it's either nil or non-empty.

Daisymoon Physics Lib


Collision Info

The returned table contains a list of collision points. Each point has the following info:

Parameter Type Description
x A number The world X position of the collision point, measured in meters.
y A number The world Y position of the collision point, measured in meters.
nx A number The collision point normal's normalized X value. Points towards the entity.
ny A number The collision point normal's normalized Y value. Points towards the entity.
impulse A number The collision impulse.
id An integer The entity identifier of the body that this entity has collided with.
userData A string If the other entity has userData in the shape that this entity has collided with, that userData will be copied to this value. This is usually nil. See Common Shape Settings.


Example


   local collisions = physics:getEntityCollisions(player.body)
   if collisions then
      for index, info in ipairs(collisions) do
          local userData = info.userData or "n/a"
          print("Collision with ".. info.id .. " at (" .. info.x .. ", " .. info.y .. "), (" ..
             info.nx .. ", " .. info.ny .. "), " .. info.impulse .. ", " userData)
      end
   end

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox