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.
Type: FUNCTION Get fixture AABB for a child shape.
Parameters
body (b2Body) - bodyfixture_index (number) - 1-based fixture index from b2d.body.get_fixtureschild_index (number) - 1-based child shape indexReturns
aabb (table) - table with lower and upperType: FUNCTION Get fixture density.
Parameters
body (b2Body) - bodyfixture_index (number) - 1-based fixture index from b2d.body.get_fixturesReturns
density (number) - density in kg/m^2Type: FUNCTION Get fixture filter data for a child shape.
Parameters
body (b2Body) - bodyfixture_index (number) - 1-based fixture index from b2d.body.get_fixtureschild_index (number) - 1-based child shape indexReturns
filter (table) - table with category_bits, mask_bits, and group_indexType: FUNCTION Get fixture friction.
Parameters
body (b2Body) - bodyfixture_index (number) - 1-based fixture index from b2d.body.get_fixturesReturns
friction (number)Type: FUNCTION Get fixture restitution.
Parameters
body (b2Body) - bodyfixture_index (number) - 1-based fixture index from b2d.body.get_fixturesReturns
restitution (number)Type: FUNCTION Get the fixture shape as a functional shape table.
Parameters
body (b2Body) - bodyfixture_index (number) - 1-based fixture index from b2d.body.get_fixturesReturns
shape (table) - shape table with numeric type from b2d.shape.SHAPE_TYPE_*,
suitable for reuse in b2d.body.create_fixture.
Circle shapes use radius and center, edge shapes use v1, v2, optional v0, v3,
polygon shapes use vertices, and chain shapes use vertices, loop, optional prev_vertex, and next_vertex.
Any angle values are in radians.Type: FUNCTION Get the fixture type.
Parameters
body (b2Body) - bodyfixture_index (number) - 1-based fixture index from b2d.body.get_fixturesReturns
type (number)Type: FUNCTION Check if a fixture is a sensor.
Parameters
body (b2Body) - bodyfixture_index (number) - 1-based fixture index from b2d.body.get_fixturesReturns
enabled (boolean)Type: FUNCTION Refilter a fixture.
Parameters
body (b2Body) - bodyfixture_index (number) - 1-based fixture index from b2d.body.get_fixturestouch_proxies (boolean) - if true, touch broad-phase proxiesType: FUNCTION Set fixture density.
Parameters
body (b2Body) - bodyfixture_index (number) - 1-based fixture index from b2d.body.get_fixturesdensity (number) - density in kg/m^2update_mass (boolean) - if true, reset body mass data after the changeType: FUNCTION Set fixture filter data for a child shape.
Parameters
body (b2Body) - bodyfixture_index (number) - 1-based fixture index from b2d.body.get_fixtureschild_index (number) - 1-based child shape indexfilter (table) - table with category_bits, mask_bits, and group_indexType: FUNCTION Set fixture friction.
Parameters
body (b2Body) - bodyfixture_index (number) - 1-based fixture index from b2d.body.get_fixturesfriction (number)Type: FUNCTION Set fixture restitution.
Parameters
body (b2Body) - bodyfixture_index (number) - 1-based fixture index from b2d.body.get_fixturesrestitution (number)Type: FUNCTION Set sensor mode for a fixture.
Parameters
body (b2Body) - bodyfixture_index (number) - 1-based fixture index from b2d.body.get_fixturesenabled (boolean)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
body (b2Body) - bodyfixture_index (number) - 1-based fixture index from b2d.body.get_fixturesshape (table) - shape table with numeric type from b2d.shape.SHAPE_TYPE_*update_mass (boolean) - if true, reset body mass data after the changeExamples
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)
Type: FUNCTION Test a point against a fixture.
Parameters
body (b2Body) - bodyfixture_index (number) - 1-based fixture index from b2d.body.get_fixturespoint (vector3) - point in world coordinatesReturns
hit (boolean)