Namespace: bullet3d.collision_object
Language: Lua
Type: Defold Lua
File: script_bullet3d_collision_object.cpp
Source: engine/gamesys/src/gamesys/scripts/bullet3d/script_bullet3d_collision_object.cpp
Functions shared by rigid bodies and trigger ghost objects. Defold keeps
ownership of each object’s user pointer, motion state, collision shape, and
world membership. Logical child shapes are inspected and mutated through
bullet3d.shape; ownership is not transferred to Lua.
Positions, distances, and CCD thresholds use Defold units. Rotations, coefficients, flags, activation state, and time values use Bullet values. Floating-point and vector inputs must be finite. CCD radii and motion thresholds must also be non-negative.
Type: FUNCTION Activate a collision object
Parameters
object (btCollisionObject) - collision objectforce (boolean) (optional) - force activation of a static or kinematic object; defaults to falseType: ENUM Collision object activation states
Members
bullet3d.collision_object.ACTIVE_TAG - Active simulation state.bullet3d.collision_object.ISLAND_SLEEPING - Sleeping simulation state.bullet3d.collision_object.WANTS_DEACTIVATION - Wants-deactivation simulation state.bullet3d.collision_object.DISABLE_DEACTIVATION - Disable automatic deactivation.bullet3d.collision_object.DISABLE_SIMULATION - Disable simulation.Type: ENUM Collision object flags
Members
bullet3d.collision_object.CF_DYNAMIC_OBJECT - Zero-valued default dynamic-object flag. Compare the complete collision-flags value with this constant; do not pass it to has_collision_flag, since zero is not a bit that can be tested.bullet3d.collision_object.CF_STATIC_OBJECT - Static collision object flag.bullet3d.collision_object.CF_KINEMATIC_OBJECT - Kinematic collision object flag.bullet3d.collision_object.CF_NO_CONTACT_RESPONSE - Disable contact response flag.bullet3d.collision_object.CF_CUSTOM_MATERIAL_CALLBACK - Custom material callback flag.bullet3d.collision_object.CF_CHARACTER_OBJECT - Character collision object flag.bullet3d.collision_object.CF_DISABLE_VISUALIZE_OBJECT - Disable debug visualization flag.bullet3d.collision_object.CF_DISABLE_SPU_COLLISION_PROCESSING - Disable SPU collision processing flag.Type: FUNCTION Force the activation state
Parameters
object (btCollisionObject) - collision objectstate (bullet3d.collision_object.ACTIVATION_STATE) - activation stateType: FUNCTION Get the activation state
Parameters
object (btCollisionObject) - collision objectReturns
state (bullet3d.collision_object.ACTIVATION_STATE) - activation stateType: FUNCTION Get the CCD motion threshold
Parameters
object (btCollisionObject) - collision objectReturns
threshold (number) - threshold in Defold unitsType: FUNCTION Get the CCD swept sphere radius
Parameters
object (btCollisionObject) - collision objectReturns
radius (number) - radius in Defold unitsType: FUNCTION Returns the raw unsigned 16-bit filter group that Defold assigned to the object’s Bullet broadphase proxy. Use this value as category_bits in a bullet3d.world query filter. Bullet applies reciprocal filtering: the query’s mask_bits must include this group, and the query’s category_bits must be included in the object’s filter mask.
Parameters
object (btCollisionObject) - collision object in a Bullet worldReturns
group (integer) - raw unsigned 16-bit collision filter groupType: FUNCTION Returns the raw unsigned 16-bit filter mask that Defold assigned to the object’s Bullet broadphase proxy. Use this value as mask_bits in a bullet3d.world query filter. Bullet applies reciprocal filtering: the query’s category_bits must be included in this mask, and the query’s mask_bits must include the object’s filter group.
Parameters
object (btCollisionObject) - collision object in a Bullet worldReturns
mask (integer) - raw unsigned 16-bit collision filter maskType: FUNCTION Get collision flags
Parameters
object (btCollisionObject) - collision objectReturns
flags (integer) - bit field of CF_* constantsType: FUNCTION Get the contact processing threshold
Parameters
object (btCollisionObject) - collision objectReturns
threshold (number) - threshold in Defold unitsType: FUNCTION Get deactivation time
Parameters
object (btCollisionObject) - collision objectReturns
seconds (number) - deactivation timeType: FUNCTION Get friction
Parameters
object (btCollisionObject) - collision objectReturns
friction (number) - friction coefficientType: FUNCTION Get the Bullet collision object type
Parameters
object (btCollisionObject) - collision objectReturns
type (bullet3d.collision_object.INTERNAL_TYPE) - native collision object typeType: FUNCTION Get the world position
Parameters
object (btCollisionObject) - collision objectReturns
position (vector3) - world position in Defold unitsType: FUNCTION Get restitution
Parameters
object (btCollisionObject) - collision objectReturns
restitution (number) - restitution coefficientType: FUNCTION Get the world rotation
Parameters
object (btCollisionObject) - collision objectReturns
rotation (quaternion) - world rotationType: FUNCTION Get the world transform
Parameters
object (btCollisionObject) - collision objectReturns
position (vector3) - world position in Defold unitsrotation (quaternion) - world rotationType: FUNCTION Test a collision flag
Parameters
object (btCollisionObject) - collision objectflag (integer) - collision flag or maskReturns
set (boolean) - true when all requested flag bits are setType: FUNCTION Test whether the object responds to contacts
Parameters
object (btCollisionObject) - collision objectReturns
result (boolean) - contact response stateType: ENUM Native collision object types
Members
bullet3d.collision_object.CO_COLLISION_OBJECT - Generic collision object type.bullet3d.collision_object.CO_RIGID_BODY - Rigid body collision object type.bullet3d.collision_object.CO_GHOST_OBJECT - Ghost collision object type.bullet3d.collision_object.CO_SOFT_BODY - Soft body collision object type.bullet3d.collision_object.CO_HF_FLUID - Height-field fluid collision object type.Type: FUNCTION This exposes Bullet’s native btCollisionObject::isActive result. It is false for ISLAND_SLEEPING and DISABLE_SIMULATION, and true for the other activation states available to Defold collision objects. It is unrelated to whether the Defold component is enabled.
Parameters
object (btCollisionObject) - collision objectReturns
active (boolean) - active stateType: FUNCTION Box2D-style name for the same simulation state returned by bullet3d.collision_object.is_active.
Parameters
object (btCollisionObject) - collision objectReturns
awake (boolean) - false when sleeping or simulation is disabledType: FUNCTION Test whether the object is a ghost trigger
Parameters
object (btCollisionObject) - collision objectReturns
result (boolean) - ghost object stateType: FUNCTION Test whether the object is kinematic
Parameters
object (btCollisionObject) - collision objectReturns
kinematic (boolean) - kinematic stateType: FUNCTION Test whether the object is a rigid body
Parameters
object (btCollisionObject) - collision objectReturns
result (boolean) - rigid body stateType: FUNCTION Test whether the object is static
Parameters
object (btCollisionObject) - collision objectReturns
static (boolean) - static stateType: FUNCTION Test whether the object is static or kinematic
Parameters
object (btCollisionObject) - collision objectReturns
result (boolean) - static or kinematic stateType: FUNCTION Test whether a collision object handle is valid
Parameters
object (btCollisionObject) - collision objectReturns
valid (boolean) - true if the native object still existsType: FUNCTION Set the activation state
Parameters
object (btCollisionObject) - collision objectstate (bullet3d.collision_object.ACTIVATION_STATE) - activation stateType: FUNCTION Passing true calls Bullet’s activate(). Passing false requests the native ISLAND_SLEEPING state. As in Bullet, static or kinematic objects are not activated without force, and protected DISABLE_DEACTIVATION or DISABLE_SIMULATION states are not replaced by a sleeping request.
Parameters
object (btCollisionObject) - collision objectawake (boolean) - requested awake stateType: FUNCTION Set the CCD motion threshold
Parameters
object (btCollisionObject) - collision objectthreshold (number) - finite non-negative threshold in Defold unitsExamples
Enable continuous collision detection for a small, fast-moving body:
function init(self)
local body = bullet3d.get_rigid_body("#collisionobject")
bullet3d.collision_object.set_ccd_swept_sphere_radius(body, 0.25)
bullet3d.collision_object.set_ccd_motion_threshold(body, 0.5)
end
Type: FUNCTION Set the CCD swept sphere radius
Parameters
object (btCollisionObject) - collision objectradius (number) - finite non-negative radius in Defold unitsType: FUNCTION Set the contact processing threshold
Parameters
object (btCollisionObject) - collision objectthreshold (number) - finite threshold in Defold unitsType: FUNCTION Set deactivation time
Parameters
object (btCollisionObject) - collision objectseconds (number) - finite deactivation timeType: FUNCTION Set friction
Parameters
object (btCollisionObject) - collision objectfriction (number) - finite friction coefficientType: FUNCTION The owning game object’s position is updated as well.
Parameters
object (btCollisionObject) - collision objectposition (vector3) - finite world position in Defold unitsType: FUNCTION Set restitution
Parameters
object (btCollisionObject) - collision objectrestitution (number) - finite restitution coefficientType: FUNCTION The owning game object’s rotation is updated as well.
Parameters
object (btCollisionObject) - collision objectrotation (quaternion) - finite, non-zero world rotation; normalized by the bindingType: FUNCTION The owning game object’s position and rotation are updated as well, so the transform persists when Defold synchronizes game objects into Bullet.
Parameters
object (btCollisionObject) - collision objectposition (vector3) - finite world position in Defold unitsrotation (quaternion) - finite, non-zero world rotation; normalized by the bindingExamples
Move a collision object while preserving its rotation:
function init(self)
local object = bullet3d.get_collision_object("#collisionobject")
local position, rotation = bullet3d.collision_object.get_world_transform(object)
bullet3d.collision_object.set_world_transform(
object,
position + vmath.vector3(0, 5, 0),
rotation)
bullet3d.collision_object.activate(object, true)
end