bullet3d.rigid_body

Namespace: bullet3d.rigid_body Language: Lua Type: Defold Lua File: script_bullet3d_rigid_body.cpp Source: engine/gamesys/src/gamesys/scripts/bullet3d/script_bullet3d_rigid_body.cpp

Rigid body functions accept the collision object userdata returned by bullet3d.get_rigid_body(). Passing a trigger ghost object raises an error. Defold retains ownership of the collision shape, motion state, world membership, and native user pointer. The shape’s logical children can be mutated through bullet3d.shape; shared resource shapes become per-instance copies on first mutation. Mass and local inertia can be changed for dynamic bodies without changing their Defold collision-object type.

Linear quantities use Defold units. Angular velocity, damping, and factors are unscaled. Torque and angular impulse use squared physics scale because inertia scales with length squared. Floating-point and vector inputs must be finite. Damping must be in [0, 1], and sleeping thresholds must be non-negative.

API

bullet3d.rigid_body.apply_central_force

Type: FUNCTION Apply a force at the center of mass

Parameters

bullet3d.rigid_body.apply_central_impulse

Type: FUNCTION Apply an impulse at the center of mass

Parameters

bullet3d.rigid_body.apply_force

Type: FUNCTION This has the same point semantics as b2d.body.apply_force: world_position is the point where the force is applied. The binding converts it to the center-of-mass-relative offset expected by Bullet’s applyForce method.

Parameters

Examples

Apply an upward force at the game object’s current world position:

function init(self)
    local body = bullet3d.get_rigid_body("#collisionobject")
    local force = vmath.vector3(0, 100, 0)
    bullet3d.rigid_body.apply_force(body, force, go.get_world_position())
end

bullet3d.rigid_body.apply_force_at_relative_position

Type: FUNCTION This exposes Bullet’s btRigidBody::applyForce point convention directly. relative_position is an offset from the body’s center of mass expressed in world axes, not a world position or body-local coordinate.

Parameters

bullet3d.rigid_body.apply_impulse

Type: FUNCTION This exposes Bullet’s btRigidBody::applyImpulse point convention directly. relative_position is an offset from the body’s center of mass expressed in world axes, not a world position or body-local coordinate.

Parameters

bullet3d.rigid_body.apply_linear_impulse

Type: FUNCTION This has the same point semantics as b2d.body.apply_linear_impulse. world_position is converted to the center-of-mass-relative offset expected by Bullet’s applyImpulse method.

Parameters

bullet3d.rigid_body.apply_torque

Type: FUNCTION Apply torque

Parameters

bullet3d.rigid_body.apply_torque_impulse

Type: FUNCTION Apply a torque impulse

Parameters

bullet3d.rigid_body.clear_forces

Type: FUNCTION Clear accumulated force and torque

Parameters

bullet3d.rigid_body.compute_aabb

Type: FUNCTION Calls Bullet’s native btRigidBody::getAabb, which immediately calculates the bounds from the body’s current collision shape and world transform. This does not read the broadphase proxy’s cached AABB.

Parameters

Returns

bullet3d.rigid_body.FLAG

Type: ENUM Combine these constants into the complete flag mask accepted by bullet3d.rigid_body.set_flags().

Members

bullet3d.rigid_body.get_angular_damping

Type: FUNCTION Get angular damping

Parameters

Returns

bullet3d.rigid_body.get_angular_factor

Type: FUNCTION Get the angular factor

Parameters

Returns

bullet3d.rigid_body.get_angular_sleeping_threshold

Type: FUNCTION Get the angular sleeping threshold

Parameters

Returns

bullet3d.rigid_body.get_angular_velocity

Type: FUNCTION Get angular velocity

Parameters

Returns

bullet3d.rigid_body.get_center_of_mass_position

Type: FUNCTION Get the center-of-mass world position

Parameters

Returns

bullet3d.rigid_body.get_damping

Type: FUNCTION Get linear and angular damping

Parameters

Returns

bullet3d.rigid_body.get_flags

Type: FUNCTION Get rigid body flags

Parameters

Returns

bullet3d.rigid_body.get_gravity

Type: FUNCTION Get body gravity

Parameters

Returns

bullet3d.rigid_body.get_inverse_mass

Type: FUNCTION Get inverse mass

Parameters

Returns

bullet3d.rigid_body.get_linear_damping

Type: FUNCTION Get linear damping

Parameters

Returns

bullet3d.rigid_body.get_linear_factor

Type: FUNCTION Get the linear factor

Parameters

Returns

bullet3d.rigid_body.get_linear_sleeping_threshold

Type: FUNCTION Get the linear sleeping threshold

Parameters

Returns

bullet3d.rigid_body.get_linear_velocity

Type: FUNCTION Get linear velocity

Parameters

Returns

bullet3d.rigid_body.get_linear_velocity_from_local_point

Type: FUNCTION This has the same point semantics as b2d.body.get_linear_velocity_from_local_point. The local origin is the body’s center of mass.

Parameters

Returns

bullet3d.rigid_body.get_linear_velocity_from_world_point

Type: FUNCTION This has the same point semantics as b2d.body.get_linear_velocity_from_world_point.

Parameters

Returns

bullet3d.rigid_body.get_local_inertia

Type: FUNCTION Returns the diagonal local inertia in Defold mass-times-distance-squared units. A zero component denotes an axis with zero inverse inertia.

Parameters

Returns

bullet3d.rigid_body.get_mass

Type: FUNCTION Get mass

Parameters

Returns

bullet3d.rigid_body.get_total_force

Type: FUNCTION Get total accumulated force

Parameters

Returns

bullet3d.rigid_body.get_total_torque

Type: FUNCTION Get total accumulated torque

Parameters

Returns

bullet3d.rigid_body.get_velocity_in_local_point

Type: FUNCTION The relative position is expressed in world axes. Despite Bullet’s function name, it is not a body-local coordinate.

Parameters

Returns

bullet3d.rigid_body.get_world

Type: FUNCTION Get the body’s world

Parameters

Returns

bullet3d.rigid_body.has_flag

Type: FUNCTION Test a rigid body flag

Parameters

Returns

bullet3d.rigid_body.is_valid

Type: FUNCTION Test whether a handle refers to a valid rigid body

Parameters

Returns

bullet3d.rigid_body.set_angular_damping

Type: FUNCTION Set angular damping

Parameters

bullet3d.rigid_body.set_angular_factor

Type: FUNCTION Set the angular factor

Parameters

bullet3d.rigid_body.set_angular_velocity

Type: FUNCTION Set angular velocity

Parameters

bullet3d.rigid_body.set_damping

Type: FUNCTION Set linear and angular damping

Parameters

bullet3d.rigid_body.set_flags

Type: FUNCTION This replaces the complete flag mask. Every enabled gyroscopic mode is evaluated independently, so clear existing gyroscopic mode bits before selecting a different mode.

Parameters

bullet3d.rigid_body.set_gravity

Type: FUNCTION A later bullet3d.world.set_gravity() call, or removing and re-adding the body to a world, can overwrite custom body gravity unless the body’s BT_DISABLE_WORLD_GRAVITY flag is set.

Parameters

Examples

Give one body persistent custom gravity without discarding its other flags:

function init(self)
    local body = bullet3d.get_rigid_body("#collisionobject")
    local flags = bullet3d.rigid_body.get_flags(body)
    flags = bit.bor(flags, bullet3d.rigid_body.BT_DISABLE_WORLD_GRAVITY)
    bullet3d.rigid_body.set_flags(body, flags)
    bullet3d.rigid_body.set_gravity(body, vmath.vector3(0, 4, 0))
end

bullet3d.rigid_body.set_linear_damping

Type: FUNCTION Set linear damping

Parameters

bullet3d.rigid_body.set_linear_factor

Type: FUNCTION Set the linear factor

Parameters

bullet3d.rigid_body.set_linear_velocity

Type: FUNCTION Set linear velocity

Parameters

bullet3d.rigid_body.set_mass

Type: FUNCTION Recalculates local inertia from the body’s current collision shape. Only a dynamic body can be changed; zero mass cannot be used to convert it into a static body. Values too small to have a finite native inverse are rejected. The body is activated after the update.

Parameters

Examples

Change the mass of a dynamic collision object and inspect its recalculated inertia:

function init(self)
    local body = bullet3d.get_rigid_body("#collisionobject")
    bullet3d.rigid_body.set_mass(body, 5)
    print("local inertia", bullet3d.rigid_body.get_local_inertia(body))
end

bullet3d.rigid_body.set_mass_properties

Type: FUNCTION Sets mass and diagonal local inertia together, updates the world-space inertia tensor, and activates the body. Only dynamic bodies are accepted. A zero inertia component is allowed and disables angular response on that local axis; negative, non-finite, or nonzero values too small to have a finite native inverse are rejected.

Parameters

bullet3d.rigid_body.set_sleeping_thresholds

Type: FUNCTION Set the sleeping thresholds

Parameters