b2d.fixture

Namespace: b2d.fixture Language: Lua Type: Defold Lua File: script_box2d_fixture_v2.cpp Source: engine/gamesys/src/gamesys/scripts/box2d/v2/script_box2d_fixture_v2.cpp

Functions for interacting with fixtures attached to Box2D bodies. Fixtures are addressed functionally by (body, fixture_index) rather than persistent Lua handles.

API

b2d.fixture.get_aabb

Type: FUNCTION Get fixture AABB for a child shape.

Parameters

Returns

b2d.fixture.get_density

Type: FUNCTION Get fixture density.

Parameters

Returns

b2d.fixture.get_filter_data

Type: FUNCTION Get fixture filter data for a child shape.

Parameters

Returns

b2d.fixture.get_friction

Type: FUNCTION Get fixture friction.

Parameters

Returns

b2d.fixture.get_restitution

Type: FUNCTION Get fixture restitution.

Parameters

Returns

b2d.fixture.get_shape

Type: FUNCTION Get the fixture shape as a functional shape table.

Parameters

Returns

b2d.fixture.get_type

Type: FUNCTION Get the fixture type.

Parameters

Returns

b2d.fixture.is_sensor

Type: FUNCTION Check if a fixture is a sensor.

Parameters

Returns

b2d.fixture.refilter

Type: FUNCTION Refilter a fixture.

Parameters

b2d.fixture.set_density

Type: FUNCTION Set fixture density.

Parameters

b2d.fixture.set_filter_data

Type: FUNCTION Set fixture filter data for a child shape.

Parameters

b2d.fixture.set_friction

Type: FUNCTION Set fixture friction.

Parameters

b2d.fixture.set_restitution

Type: FUNCTION Set fixture restitution.

Parameters

b2d.fixture.set_sensor

Type: FUNCTION Set sensor mode for a fixture.

Parameters

b2d.fixture.set_shape

Type: FUNCTION This updates the existing Box2D v2 shape using the same table format as b2d.body.create_fixture and b2d.fixture.get_shape. The shape type must match the current fixture shape type. Polygon updates must keep the same vertex count. Chain shape geometry cannot be updated in-place. The body mass is not updated unless update_mass is true.

Parameters

Examples

local body = b2d.get_body("#collisionobject")

-- Move a circle shape relative to the body origin.
local circle = b2d.fixture.get_shape(body, 1)
circle.center = vmath.vector3(24, 0, 0)
b2d.fixture.set_shape(body, 1, circle, true)

-- Replace an edge shape's local endpoints.
b2d.fixture.set_shape(body, 2, {
    type = b2d.shape.SHAPE_TYPE_EDGE,
    v1 = vmath.vector3(-32, 0, 0),
    v2 = vmath.vector3( 32, 0, 0),
})

-- Update a box shape using the polygon box convenience format.
-- The existing polygon must already have four vertices.
b2d.fixture.set_shape(body, 3, {
    type = b2d.shape.SHAPE_TYPE_BOX,
    hx = 16,
    hy = 8,
    center = vmath.vector3(0, 20, 0),
    angle = math.rad(30),
}, true)

b2d.fixture.test_point

Type: FUNCTION Test a point against a fixture.

Parameters

Returns