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 (integer) - 1-based fixture index from b2d.body.get_fixtureschild_index (integer) - 1-based child shape indexReturns
aabb (b2d.aabb) - the fixture AABBType: FUNCTION Get fixture density.
Parameters
body (b2Body) - bodyfixture_index (integer) - 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 (integer) - 1-based fixture index from b2d.body.get_fixtureschild_index (integer) - 1-based child shape indexReturns
filter (b2d.filter) - the filter dataType: FUNCTION Get fixture friction.
Parameters
body (b2Body) - bodyfixture_index (integer) - 1-based fixture index from b2d.body.get_fixturesReturns
friction (number)Type: FUNCTION Get fixture restitution.
Parameters
body (b2Body) - bodyfixture_index (integer) - 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 (integer) - 1-based fixture index from b2d.body.get_fixturesReturns
shape (b2d.shape.definition) - the shape definition, suitable for reuse in b2d.body.create_fixtureType: FUNCTION Get the fixture type.
Parameters
body (b2Body) - bodyfixture_index (integer) - 1-based fixture index from b2d.body.get_fixturesReturns
type (b2d.shape.SHAPE_TYPE)Type: FUNCTION Check if a fixture is a sensor.
Parameters
body (b2Body) - bodyfixture_index (integer) - 1-based fixture index from b2d.body.get_fixturesReturns
enabled (boolean)Type: FUNCTION Refilter a fixture.
Parameters
body (b2Body) - bodyfixture_index (integer) - 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 (integer) - 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 (integer) - 1-based fixture index from b2d.body.get_fixtureschild_index (integer) - 1-based child shape indexfilter (b2d.filter) - the filter dataType: FUNCTION Set fixture friction.
Parameters
body (b2Body) - bodyfixture_index (integer) - 1-based fixture index from b2d.body.get_fixturesfriction (number)Type: FUNCTION Set fixture restitution.
Parameters
body (b2Body) - bodyfixture_index (integer) - 1-based fixture index from b2d.body.get_fixturesrestitution (number)Type: FUNCTION Set sensor mode for a fixture.
Parameters
body (b2Body) - bodyfixture_index (integer) - 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 (integer) - 1-based fixture index from b2d.body.get_fixturesshape (b2d.shape.definition) - the shape definitionupdate_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 (integer) - 1-based fixture index from b2d.body.get_fixturespoint (vector3) - point in world coordinatesReturns
hit (boolean)