Defold Learn logo


Box2D b2Body documentation

Functions for interacting with Box2D bodies.

Version: alpha

TYPES
b2Body Box2D body
b2World Box2D world
ENUMS
b2d.body.B2 Body types
FUNCTIONS
b2d.body.apply_angular_impulse() Apply an angular impulse.
b2d.body.apply_angular_impulse() Apply an angular impulse.
b2d.body.apply_force() Apply a force at a world point. If the force is no...
b2d.body.apply_force() Apply a force at a world point. If the force is no...
b2d.body.apply_force_to_center() Apply a force to the center of mass. This wakes up the body.
b2d.body.apply_force_to_center() Apply a force to the center of mass. This wakes up the body.
b2d.body.apply_linear_impulse() Apply an impulse at a point. This immediately modi...
b2d.body.apply_linear_impulse() Apply an impulse at a point. This immediately modi...
b2d.body.apply_linear_impulse_to_center() Apply a linear impulse to the center of mass.
b2d.body.apply_torque() Apply a torque. This affects the angular velocity ...
b2d.body.apply_torque() Apply a torque. This affects the angular velocity ...
b2d.body.compute_aabb() Compute the world AABB of all body shapes.
b2d.body.create_chain() Create a chain and attach its segment shapes to this body.
b2d.body.create_fixture() Creates a fixture and attach it to this body. Use ...
b2d.body.create_fixture() Creates a fixture from a shape and attach it to th...
b2d.body.create_shape() Creates a shape and attaches it to this body
b2d.body.destroy_fixture() Destroy a fixture from a body.
b2d.body.destroy_shape() Destroy a shape. This removes the shape from the b...
b2d.body.dump() Print the body representation to the log output
b2d.body.enable_contact_events() Enable or disable contact events on all body shapes.
b2d.body.enable_hit_events() Enable or disable hit events on all body shapes.
b2d.body.enable_sleep() You can disable sleeping on this body. If you disable sleeping, the body will be woken.
b2d.body.get_angle() Get the angle in radians.
b2d.body.get_angle() Get the angle in radians.
b2d.body.get_angular_damping() Get the angular damping of the body.
b2d.body.get_angular_damping() Get the angular damping of the body.
b2d.body.get_angular_velocity() Get the angular velocity.
b2d.body.get_angular_velocity() Get the angular velocity.
b2d.body.get_contact_data() Get touching contact data for a body.
b2d.body.get_fixtures() Get the fixtures attached to this body.
b2d.body.get_force() Get the total force currently applied on this object
b2d.body.get_force() Get the total force currently applied on this object
b2d.body.get_gravity_scale() Get the gravity scale of the body.
b2d.body.get_gravity_scale() Get the gravity scale of the body.
b2d.body.get_inertia() Get the rotational inertia of the body about the local origin.
b2d.body.get_joints() Get the joints attached to this body.
b2d.body.get_joints() Get the joints attached to this body.
b2d.body.get_linear_damping() Get the linear damping of the body.
b2d.body.get_linear_damping() Get the linear damping of the body.
b2d.body.get_linear_velocity() Get the linear velocity of the center of mass.
b2d.body.get_linear_velocity() Get the linear velocity of the center of mass.
b2d.body.get_linear_velocity_from_local_point() Get the world velocity of a local point.
b2d.body.get_linear_velocity_from_local_point() Get the world velocity of a local point.
b2d.body.get_linear_velocity_from_world_point() Get the world linear velocity of a world point attached to this body.
b2d.body.get_linear_velocity_from_world_point() Get the world linear velocity of a world point attached to this body.
b2d.body.get_local_center() Get the local position of the center of mass.
b2d.body.get_local_center_of_mass() Get the local position of the center of mass.
b2d.body.get_local_point() Gets a local point relative to the body's origin given a world point.
b2d.body.get_local_point() Gets a local point relative to the body's origin given a world point.
b2d.body.get_local_vector() Gets a local vector given a world vector.
b2d.body.get_local_vector() Gets a local vector given a world vector.
b2d.body.get_mass() Get the total mass of the body.
b2d.body.get_mass() Get the total mass of the body.
b2d.body.get_mass_data() Get the mass data of the body.
b2d.body.get_mass_data() Get the mass data of the body.
b2d.body.get_name() Get the body name.
b2d.body.get_next() Get the next body in the world's body list.
b2d.body.get_position() Get the world body origin position.
b2d.body.get_position() Get the world body origin position.
b2d.body.get_rotational_inertia() Get the rotational inertia of the body about the local origin.
b2d.body.get_shapes() Get the list of all shapes attached to this body.
b2d.body.get_sleep_threshold() Get the sleep velocity threshold.
b2d.body.get_transform() Get the body transform for the body's origin.
b2d.body.get_transform() Get the body transform for the body's origin.
b2d.body.get_type() Get the type of this body.
b2d.body.get_type() Get the type of this body.
b2d.body.get_user_data() Get the user data pointer that was provided in the body definition.
b2d.body.get_world() Get the parent world of this body.
b2d.body.get_world() Get the parent world of this body.
b2d.body.get_world_center() Get the world position of the center of mass.
b2d.body.get_world_center_of_mass() Get the world position of the center of mass.
b2d.body.get_world_point() Get the world coordinates of a point given the local coordinates.
b2d.body.get_world_point() Get the world coordinates of a point given the local coordinates.
b2d.body.get_world_vector() Get the world coordinates of a vector given the local coordinates.
b2d.body.get_world_vector() Get the world coordinates of a vector given the local coordinates.
b2d.body.is_active() Get the active state of the body.
b2d.body.is_active() Get the active state of the body.
b2d.body.is_awake() Get the sleeping state of this body.
b2d.body.is_awake() Get the sleeping state of this body.
b2d.body.is_bullet() Is this body in bullet mode
b2d.body.is_bullet() Is this body in bullet mode
b2d.body.is_fixed_rotation() Does this body have fixed rotation?
b2d.body.is_fixed_rotation() Does this body have fixed rotation?
b2d.body.is_sleeping_allowed() Is this body allowed to sleep
b2d.body.is_sleeping_enabled() Is this body allowed to sleep
b2d.body.is_valid() Validate a body handle.
b2d.body.reset_mass_data() This resets the mass properties to the sum of the ...
b2d.body.reset_mass_data() This resets the mass properties to the sum of the ...
b2d.body.set_active() Set the active state of the body
b2d.body.set_active() Set the active state of the body
b2d.body.set_angular_damping() Set the angular damping of the body.
b2d.body.set_angular_damping() Set the angular damping of the body.
b2d.body.set_angular_velocity() Set the angular velocity.
b2d.body.set_angular_velocity() Set the angular velocity.
b2d.body.set_awake() Set the sleep state of the body. A sleeping body has very low CPU cost.
b2d.body.set_awake() Set the sleep state of the body. A sleeping body has very low CPU cost.
b2d.body.set_bullet() Should this body be treated like a bullet for continuous collision detection?
b2d.body.set_bullet() Should this body be treated like a bullet for continuous collision detection?
b2d.body.set_fixed_rotation() Set this body to have fixed rotation. This causes the mass to be reset.
b2d.body.set_fixed_rotation() Set this body to have fixed rotation. This causes the mass to be reset.
b2d.body.set_gravity_scale() Set the gravity scale of the body.
b2d.body.set_gravity_scale() Set the gravity scale of the body.
b2d.body.set_linear_damping() Set the linear damping of the body.
b2d.body.set_linear_damping() Set the linear damping of the body.
b2d.body.set_linear_velocity() Set the linear velocity of the center of mass.
b2d.body.set_linear_velocity() Set the linear velocity of the center of mass.
b2d.body.set_mass_data() Set the mass properties to override the mass prope...
b2d.body.set_mass_data() Set the mass properties to override the mass prope...
b2d.body.set_name() Set the body name.
b2d.body.set_sleep_threshold() Set the sleep velocity threshold.
b2d.body.set_sleeping_allowed() You can disable sleeping on this body. If you disable sleeping, the body will be woken.
b2d.body.set_target_transform() Set velocity to reach a target transform.
b2d.body.set_transform() Set the position of the body's origin and rotation
b2d.body.set_transform() Set the position of the body's origin and rotation
b2d.body.set_type() Set the type of this body. This may alter the mass and velocity.
b2d.body.set_type() Set the type of this body. This may alter the mass and velocity.
b2d.body.set_user_data() Set the user data. Use this to store your application specific data.

Types

b2Body

b2Body = userdata

An opaque handle to the native Box2D body of a collision-object component. Obtain it with b2d.get_body and pass it to functions in b2d.body. The collision object owns the body, so use b2d.body.is_valid before retaining a handle across deletion or collection changes.

EXAMPLES

local body = b2d.get_body("#collisionobject")
if body and b2d.body.is_valid(body) then
    b2d.body.apply_force_to_center(body, vmath.vector3(0, 100, 0))
end

b2World

b2World = userdata

An opaque handle to the Box2D physics world owned by a collection. Obtain the current collection's world with b2d.get_world, or the world that owns a body with b2d.body.get_world. Pass the handle to functions in b2d.world; it cannot be constructed directly from Lua.

EXAMPLES

local world = b2d.get_world()
if world then
    print(b2d.world.get_gravity(world))
end

Enums

b2d.body.B2

b2d.body.B2: integer

Body types

VALUES

b2d.body.B2_DYNAMIC_BODY Dynamic body
b2d.body.B2_KINEMATIC_BODY Kinematic body
b2d.body.B2_STATIC_BODY Static (immovable) body

Functions

b2d.body.apply_angular_impulse()

b2d.body.apply_angular_impulse(body:b2Body, impulse:number)

Apply an angular impulse.

PARAMETERS

body b2Body
body
impulse number
impulse the angular impulse in units of kgmm/s

b2d.body.apply_angular_impulse()

b2d.body.apply_angular_impulse(body:b2Body, impulse:number)

Apply an angular impulse.

PARAMETERS

body b2Body
body
impulse number
impulse the angular impulse in units of kgmm/s

b2d.body.apply_force()

b2d.body.apply_force(body:b2Body, force:vector3, point:vector3)

Apply a force at a world point. If the force is not applied at the center of mass, it will generate a torque and affect the angular velocity. This wakes up the body.

PARAMETERS

body b2Body
body
force vector3
the world force vector, usually in Newtons (N).
point vector3
the world position of the point of application.

b2d.body.apply_force()

b2d.body.apply_force(body:b2Body, force:vector3, point:vector3)

Apply a force at a world point. If the force is not applied at the center of mass, it will generate a torque and affect the angular velocity. This wakes up the body.

PARAMETERS

body b2Body
body
force vector3
the world force vector, usually in Newtons (N).
point vector3
the world position of the point of application.

b2d.body.apply_force_to_center()

b2d.body.apply_force_to_center(body:b2Body, force:vector3)

Apply a force to the center of mass. This wakes up the body.

PARAMETERS

body b2Body
body
force vector3
the world force vector, usually in Newtons (N).

b2d.body.apply_force_to_center()

b2d.body.apply_force_to_center(body:b2Body, force:vector3)

Apply a force to the center of mass. This wakes up the body.

PARAMETERS

body b2Body
body
force vector3
the world force vector, usually in Newtons (N).

b2d.body.apply_linear_impulse()

b2d.body.apply_linear_impulse(body:b2Body, impulse:vector3, point:vector3)

Apply an impulse at a point. This immediately modifies the velocity. It also modifies the angular velocity if the point of application is not at the center of mass. This wakes up the body.

PARAMETERS

body b2Body
body
impulse vector3
the world impulse vector, usually in N-seconds or kg-m/s.
point vector3
the world position of the point of application.

b2d.body.apply_linear_impulse()

b2d.body.apply_linear_impulse(body:b2Body, impulse:vector3, point:vector3)

Apply an impulse at a point. This immediately modifies the velocity. It also modifies the angular velocity if the point of application is not at the center of mass. This wakes up the body.

PARAMETERS

body b2Body
body
impulse vector3
the world impulse vector, usually in N-seconds or kg-m/s.
point vector3
the world position of the point of application.

b2d.body.apply_linear_impulse_to_center()

b2d.body.apply_linear_impulse_to_center(body:b2Body, impulse:vector3)

Apply a linear impulse to the center of mass.

PARAMETERS

body b2Body
body
impulse vector3
world impulse vector

b2d.body.apply_torque()

b2d.body.apply_torque(body:b2Body, torque:number)

Apply a torque. This affects the angular velocity without affecting the linear velocity of the center of mass. This wakes up the body.

PARAMETERS

body b2Body
body
torque number
torque about the z-axis (out of the screen), usually in N-m.

b2d.body.apply_torque()

b2d.body.apply_torque(body:b2Body, torque:number)

Apply a torque. This affects the angular velocity without affecting the linear velocity of the center of mass. This wakes up the body.

PARAMETERS

body b2Body
body
torque number
torque about the z-axis (out of the screen), usually in N-m.

b2d.body.compute_aabb()

b2d.body.compute_aabb(body:b2Body)→aabb:b2d.aabb

Compute the world AABB of all body shapes.

PARAMETERS

body b2Body
body

RETURNS

aabb b2d.aabb
body bounds

b2d.body.create_chain()

b2d.body.create_chain(body:b2Body, definition:b2d.chain_definition)→(chain:b2Chain, segments:b2d.shape_info[])

Chains are one-sided connected segments with optional ghost vertices at the ends of open chains. Ghost vertices are creation-time chain data only and cannot be added to arbitrary shapes, bodies, or joints after creation.

PARAMETERS

body b2Body
body
definition b2d.chain_definition
the chain definition

RETURNS

chain b2Chain
created chain handle
segments b2d.shape_info[]
created chain segments

EXAMPLES

local chain, segments = b2d.body.create_chain(body, {
    vertices = {
        vmath.vector3(-64, 0, 0),
        vmath.vector3(0, 16, 0),
        vmath.vector3(64, 0, 0),
    },
    prev_vertex = vmath.vector3(-96, 0, 0),
    next_vertex = vmath.vector3(96, 0, 0),
    friction = 0.6,
})

b2d.body.create_fixture()

b2d.body.create_fixture(body:b2Body, definition:b2d.fixture_definition)→fixture:b2d.fixture_info

Creates a fixture and attach it to this body. Use this function if you need to set some fixture parameters, like friction. Otherwise you can create the fixture directly from a shape. If the density is non-zero, this function automatically updates the mass of the body. Contacts are not created until the next time step.

PARAMETERS

body b2Body
body
definition b2d.fixture_definition
fixture definition

RETURNS

fixture b2d.fixture_info
fixture information

EXAMPLES

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

local triangle = b2d.body.create_fixture(body, {
    density = 1.0,
    friction = 0.3,
    shape = {
        type = b2d.shape.SHAPE_TYPE_POLYGON,
        vertices = {
            vmath.vector3(-16, -16, 0),
            vmath.vector3( 16, -16, 0),
            vmath.vector3(  0,  16, 0),
        },
    },
})

b2d.body.create_fixture()

b2d.body.create_fixture(body:b2Body, shape:b2Shape, density:number)

Creates a fixture from a shape and attach it to this body. This is a convenience function. Use b2FixtureDef if you need to set parameters like friction, restitution, user data, or filtering. If the density is non-zero, this function automatically updates the mass of the body.

PARAMETERS

body b2Body
body
shape b2Shape
the shape to be cloned.
density number
the shape density (set to zero for static bodies).

b2d.body.create_shape()

b2d.body.create_shape(body:b2Body, definition:b2d.shape_create_definition)

Creates a shape and attaches it to this body. If the density is non-zero, this function automatically updates the mass of the body. Contacts are not created until the next time step.

PARAMETERS

body b2Body
body
definition b2d.shape_create_definition
the shape definition.

b2d.body.destroy_fixture()

b2d.body.destroy_fixture(body:b2Body, fixture_index:integer)

Destroy a fixture from a body.

PARAMETERS

body b2Body
body
fixture_index integer
1-based fixture index from b2d.body.get_fixtures

b2d.body.destroy_shape()

b2d.body.destroy_shape(body:b2Body, shape_index:integer)

Destroy a shape. This removes the shape from the broad-phase and destroys all contacts associated with this shape. This will automatically adjust the mass of the body if the body is dynamic and the shape has positive density. All shapes attached to a body are implicitly destroyed when the body is destroyed.

PARAMETERS

body b2Body
body
shape_index integer
1-based shape index from b2d.body.get_shapes

b2d.body.dump()

b2d.body.dump(body:b2Body)

Print the body representation to the log output

PARAMETERS

body b2Body
body

b2d.body.enable_contact_events()

b2d.body.enable_contact_events(body:b2Body, enable:boolean)

Enable or disable contact events on all body shapes.

PARAMETERS

body b2Body
body
enable boolean
true to enable contact events

b2d.body.enable_hit_events()

b2d.body.enable_hit_events(body:b2Body, enable:boolean)

Enable or disable hit events on all body shapes.

PARAMETERS

body b2Body
body
enable boolean
true to enable hit events

b2d.body.enable_sleep()

b2d.body.enable_sleep(body:b2Body, enable:boolean)

You can disable sleeping on this body. If you disable sleeping, the body will be woken.

PARAMETERS

body b2Body
body
enable boolean
if false, the body will never sleep, and consume more CPU

b2d.body.get_angle()

b2d.body.get_angle(body:b2Body)→angle:number

Get the angle in radians.

PARAMETERS

body b2Body
body

RETURNS

angle number
the current world rotation angle in radians.

b2d.body.get_angle()

b2d.body.get_angle(body:b2Body)→angle:number

Get the angle in radians.

PARAMETERS

body b2Body
body

RETURNS

angle number
the current world rotation angle in radians.

b2d.body.get_angular_damping()

b2d.body.get_angular_damping(body:b2Body)→damping:number

Get the angular damping of the body.

PARAMETERS

body b2Body
body

RETURNS

damping number
the damping

b2d.body.get_angular_damping()

b2d.body.get_angular_damping(body:b2Body)→damping:number

Get the angular damping of the body.

PARAMETERS

body b2Body
body

RETURNS

damping number
the damping

b2d.body.get_angular_velocity()

b2d.body.get_angular_velocity(body:b2Body)→velocity:number

Get the angular velocity.

PARAMETERS

body b2Body
body

RETURNS

velocity number
the angular velocity in radians/second.

b2d.body.get_angular_velocity()

b2d.body.get_angular_velocity(body:b2Body)→velocity:number

Get the angular velocity.

PARAMETERS

body b2Body
body

RETURNS

velocity number
the angular velocity in radians/second.

b2d.body.get_contact_data()

b2d.body.get_contact_data(body:b2Body)→contacts:b2d.contact_data[]

Get touching contact data for a body.

PARAMETERS

body b2Body
body

RETURNS

contacts b2d.contact_data[]
array of contact tables

b2d.body.get_fixtures()

b2d.body.get_fixtures(body:b2Body)→fixtures:b2d.fixture_info[]

Get the fixtures attached to this body.

PARAMETERS

body b2Body
body

RETURNS

fixtures b2d.fixture_info[]
the attached fixtures

b2d.body.get_force()

b2d.body.get_force(body:b2Body)→force:vector3

Get the total force currently applied on this object

PARAMETERS

body b2Body
body

RETURNS

force vector3

b2d.body.get_force()

b2d.body.get_force(body:b2Body)→force:vector3

Get the total force currently applied on this object

PARAMETERS

body b2Body
body

RETURNS

force vector3

b2d.body.get_gravity_scale()

b2d.body.get_gravity_scale(body:b2Body)→scale:number

Get the gravity scale of the body.

PARAMETERS

body b2Body
body

RETURNS

scale number
the scale

b2d.body.get_gravity_scale()

b2d.body.get_gravity_scale(body:b2Body)→scale:number

Get the gravity scale of the body.

PARAMETERS

body b2Body
body

RETURNS

scale number
the scale

b2d.body.get_inertia()

b2d.body.get_inertia(body:b2Body)→inertia:number

Get the rotational inertia of the body about the local origin.

PARAMETERS

body b2Body
body

RETURNS

inertia number
the rotational inertia, usually in kg-m^2.

b2d.body.get_joints()

b2d.body.get_joints(body:b2Body)→joints:b2Joint[]

Get the joints attached to this body.

PARAMETERS

body b2Body
body

RETURNS

joints b2Joint[]
joint handles created by b2d.joint

b2d.body.get_joints()

b2d.body.get_joints(body:b2Body)→joints:b2Joint[]

Get the joints attached to this body.

PARAMETERS

body b2Body
body

RETURNS

joints b2Joint[]
joint handles created by b2d.joint

b2d.body.get_linear_damping()

b2d.body.get_linear_damping(body:b2Body)→damping:number

Get the linear damping of the body.

PARAMETERS

body b2Body
body

RETURNS

damping number
the damping

b2d.body.get_linear_damping()

b2d.body.get_linear_damping(body:b2Body)→damping:number

Get the linear damping of the body.

PARAMETERS

body b2Body
body

RETURNS

damping number
the damping

b2d.body.get_linear_velocity()

b2d.body.get_linear_velocity(body:b2Body)→velocity:vector3

Get the linear velocity of the center of mass.

PARAMETERS

body b2Body
body

RETURNS

velocity vector3
the linear velocity of the center of mass.

b2d.body.get_linear_velocity()

b2d.body.get_linear_velocity(body:b2Body)→velocity:vector3

Get the linear velocity of the center of mass.

PARAMETERS

body b2Body
body

RETURNS

velocity vector3
the linear velocity of the center of mass.

b2d.body.get_linear_velocity_from_local_point()

b2d.body.get_linear_velocity_from_local_point(body:b2Body, local_point:vector3)→velocity:vector3

Get the world velocity of a local point.

PARAMETERS

body b2Body
body
local_point vector3
a point in local coordinates.

RETURNS

velocity vector3
the world velocity of a point.

b2d.body.get_linear_velocity_from_local_point()

b2d.body.get_linear_velocity_from_local_point(body:b2Body, local_point:vector3)→velocity:vector3

Get the world velocity of a local point.

PARAMETERS

body b2Body
body
local_point vector3
a point in local coordinates.

RETURNS

velocity vector3
the world velocity of a point.

b2d.body.get_linear_velocity_from_world_point()

b2d.body.get_linear_velocity_from_world_point(body:b2Body, world_point:vector3)→velocity:vector3

Get the world linear velocity of a world point attached to this body.

PARAMETERS

body b2Body
body
world_point vector3
a point in world coordinates.

RETURNS

velocity vector3
the world velocity of a point.

b2d.body.get_linear_velocity_from_world_point()

b2d.body.get_linear_velocity_from_world_point(body:b2Body, world_point:vector3)→velocity:vector3

Get the world linear velocity of a world point attached to this body.

PARAMETERS

body b2Body
body
world_point vector3
a point in world coordinates.

RETURNS

velocity vector3
the world velocity of a point.

b2d.body.get_local_center()

b2d.body.get_local_center(body:b2Body)→center:vector3

Get the local position of the center of mass.

PARAMETERS

body b2Body
body

RETURNS

center vector3
Get the local position of the center of mass.

b2d.body.get_local_center_of_mass()

b2d.body.get_local_center_of_mass(body:b2Body)→center:vector3

Get the local position of the center of mass.

PARAMETERS

body b2Body
body

RETURNS

center vector3
Get the local position of the center of mass.

b2d.body.get_local_point()

b2d.body.get_local_point(body:b2Body, world_point:vector3)→vector:vector3

Gets a local point relative to the body's origin given a world point.

PARAMETERS

body b2Body
body
world_point vector3
a point in world coordinates.

RETURNS

vector vector3
the corresponding local point relative to the body's origin.

b2d.body.get_local_point()

b2d.body.get_local_point(body:b2Body, world_point:vector3)→vector:vector3

Gets a local point relative to the body's origin given a world point.

PARAMETERS

body b2Body
body
world_point vector3
a point in world coordinates.

RETURNS

vector vector3
the corresponding local point relative to the body's origin.

b2d.body.get_local_vector()

b2d.body.get_local_vector(body:b2Body, world_vector:vector3)→vector:vector3

Gets a local vector given a world vector.

PARAMETERS

body b2Body
body
world_vector vector3
a vector in world coordinates.

RETURNS

vector vector3
the corresponding local vector.

b2d.body.get_local_vector()

b2d.body.get_local_vector(body:b2Body, world_vector:vector3)→vector:vector3

Gets a local vector given a world vector.

PARAMETERS

body b2Body
body
world_vector vector3
a vector in world coordinates.

RETURNS

vector vector3
the corresponding local vector.

b2d.body.get_mass()

b2d.body.get_mass(body:b2Body)→mass:number

Get the total mass of the body.

PARAMETERS

body b2Body
body

RETURNS

mass number
the mass, usually in kilograms (kg).

b2d.body.get_mass()

b2d.body.get_mass(body:b2Body)→mass:number

Get the total mass of the body.

PARAMETERS

body b2Body
body

RETURNS

mass number
the mass, usually in kilograms (kg).

b2d.body.get_mass_data()

b2d.body.get_mass_data(body:b2Body)→data:b2d.mass_data

Get the mass data of the body.

PARAMETERS

body b2Body
body

RETURNS

data b2d.mass_data
the mass data

b2d.body.get_mass_data()

b2d.body.get_mass_data(body:b2Body)→data:b2MassData

Get the mass data of the body.

PARAMETERS

body b2Body
body

RETURNS

data b2MassData
a struct containing the mass, inertia and center of the body.

b2d.body.get_name()

b2d.body.get_name(body:b2Body)→name:string|nil

Get the body name.

PARAMETERS

body b2Body
body

RETURNS

name string
nil
body name, or nil if no name is set

b2d.body.get_next()

b2d.body.get_next(body:b2Body)→body:b2Body|nil

Get the next body in the world's body list.

PARAMETERS

body b2Body
body

RETURNS

body b2Body
nil
the next body, or nil if this is the last body

b2d.body.get_position()

b2d.body.get_position(body:b2Body)→position:vector3

Get the world body origin position.

PARAMETERS

body b2Body
body

RETURNS

position vector3
the world position of the body's origin.

b2d.body.get_position()

b2d.body.get_position(body:b2Body)→position:vector3

Get the world body origin position.

PARAMETERS

body b2Body
body

RETURNS

position vector3
the world position of the body's origin.

b2d.body.get_rotational_inertia()

b2d.body.get_rotational_inertia(body:b2Body)→inertia:number

Get the rotational inertia of the body about the local origin.

PARAMETERS

body b2Body
body

RETURNS

inertia number
the rotational inertia, usually in kg-m^2.

b2d.body.get_shapes()

b2d.body.get_shapes(body:b2Body)→shapes:b2d.shape_info[]

Get the list of all shapes attached to this body.

PARAMETERS

body b2Body
body

RETURNS

shapes b2d.shape_info[]
attached shapes

b2d.body.get_sleep_threshold()

b2d.body.get_sleep_threshold(body:b2Body)→threshold:number

Get the sleep velocity threshold.

PARAMETERS

body b2Body
body

RETURNS

threshold number
velocity threshold in Defold units per second

b2d.body.get_transform()

b2d.body.get_transform(body:b2Body)→transform:b2d.transform

Get the body transform for the body's origin.

PARAMETERS

body b2Body
body

RETURNS

transform b2d.transform
the body transform

b2d.body.get_transform()

b2d.body.get_transform(body:b2Body)→transform:b2Transform

Get the body transform for the body's origin.

PARAMETERS

body b2Body
body

RETURNS

transform b2Transform
the world position of the body's origin.

b2d.body.get_type()

b2d.body.get_type(body:b2Body)→type:b2BodyType

Get the type of this body.

PARAMETERS

body b2Body
body

RETURNS

type b2BodyType
the body type

b2d.body.get_type()

b2d.body.get_type(body:b2Body)→type:b2BodyType

Get the type of this body.

PARAMETERS

body b2Body
body

RETURNS

type b2BodyType
the body type

b2d.body.get_user_data()

b2d.body.get_user_data(body:b2Body)→id:hash

Get the user data pointer that was provided in the body definition.

PARAMETERS

body b2Body
body

RETURNS

id hash
the game object id this body is connected to

b2d.body.get_world()

b2d.body.get_world(body:b2Body)→world:b2World

Get the parent world of this body.

PARAMETERS

body b2Body
body

RETURNS

world b2World

b2d.body.get_world()

b2d.body.get_world(body:b2Body)→world:b2World

Get the parent world of this body.

PARAMETERS

body b2Body
body

RETURNS

world b2World

b2d.body.get_world_center()

b2d.body.get_world_center(body:b2Body)→center:vector3

Get the world position of the center of mass.

PARAMETERS

body b2Body
body

RETURNS

center vector3
Get the world position of the center of mass.

b2d.body.get_world_center_of_mass()

b2d.body.get_world_center_of_mass(body:b2Body)→center:vector3

Get the world position of the center of mass.

PARAMETERS

body b2Body
body

RETURNS

center vector3
Get the world position of the center of mass.

b2d.body.get_world_point()

b2d.body.get_world_point(body:b2Body, local_vector:vector3)→vector:vector3

Get the world coordinates of a point given the local coordinates.

PARAMETERS

body b2Body
body
local_vector vector3
localPoint a point on the body measured relative the the body's origin.

RETURNS

vector vector3
the same point expressed in world coordinates.

b2d.body.get_world_point()

b2d.body.get_world_point(body:b2Body, local_vector:vector3)→vector:vector3

Get the world coordinates of a point given the local coordinates.

PARAMETERS

body b2Body
body
local_vector vector3
localPoint a point on the body measured relative the the body's origin.

RETURNS

vector vector3
the same point expressed in world coordinates.

b2d.body.get_world_vector()

b2d.body.get_world_vector(body:b2Body, local_vector:vector3)→vector:vector3

Get the world coordinates of a vector given the local coordinates.

PARAMETERS

body b2Body
body
local_vector vector3
a vector fixed in the body.

RETURNS

vector vector3
the same vector expressed in world coordinates.

b2d.body.get_world_vector()

b2d.body.get_world_vector(body:b2Body, local_vector:vector3)→vector:vector3

Get the world coordinates of a vector given the local coordinates.

PARAMETERS

body b2Body
body
local_vector vector3
a vector fixed in the body.

RETURNS

vector vector3
the same vector expressed in world coordinates.

b2d.body.is_active()

b2d.body.is_active(body:b2Body)→enabled:boolean

Get the active state of the body.

PARAMETERS

body b2Body
body

RETURNS

enabled boolean
is the body active

b2d.body.is_active()

b2d.body.is_active(body:b2Body)→enabled:boolean

Get the active state of the body.

PARAMETERS

body b2Body
body

RETURNS

enabled boolean
is the body active

b2d.body.is_awake()

b2d.body.is_awake(body:b2Body)→enabled:boolean

Get the sleeping state of this body.

PARAMETERS

body b2Body
body

RETURNS

enabled boolean
true if the body is awake, false if it's sleeping.

b2d.body.is_awake()

b2d.body.is_awake(body:b2Body)→enabled:boolean

Get the sleeping state of this body.

PARAMETERS

body b2Body
body

RETURNS

enabled boolean
true if the body is awake, false if it's sleeping.

b2d.body.is_bullet()

b2d.body.is_bullet(body:b2Body)→enabled:boolean

Is this body in bullet mode

PARAMETERS

body b2Body
body

RETURNS

enabled boolean
true if the body is in bullet mode

b2d.body.is_bullet()

b2d.body.is_bullet(body:b2Body)→enabled:boolean

Is this body in bullet mode

PARAMETERS

body b2Body
body

RETURNS

enabled boolean
true if the body is in bullet mode

b2d.body.is_fixed_rotation()

b2d.body.is_fixed_rotation(body:b2Body)→enabled:boolean

Does this body have fixed rotation?

PARAMETERS

body b2Body
body

RETURNS

enabled boolean
is the rotation fixed

b2d.body.is_fixed_rotation()

b2d.body.is_fixed_rotation(body:b2Body)→enabled:boolean

Does this body have fixed rotation?

PARAMETERS

body b2Body
body

RETURNS

enabled boolean
is the rotation fixed

b2d.body.is_sleeping_allowed()

b2d.body.is_sleeping_allowed(body:b2Body)→enabled:boolean

Is this body allowed to sleep

PARAMETERS

body b2Body
body

RETURNS

enabled boolean
true if the body is allowed to sleep

b2d.body.is_sleeping_enabled()

b2d.body.is_sleeping_enabled(body:b2Body)→enabled:boolean

Is this body allowed to sleep

PARAMETERS

body b2Body
body

RETURNS

enabled boolean
true if the body is allowed to sleep

b2d.body.is_valid()

b2d.body.is_valid(body:b2Body)→valid:boolean

Validate a body handle.

PARAMETERS

body b2Body
body

RETURNS

valid boolean
true if the body handle still refers to a live Box2D body

b2d.body.reset_mass_data()

b2d.body.reset_mass_data(body:b2Body)

This resets the mass properties to the sum of the mass properties of the fixtures. This normally does not need to be called unless you called SetMassData to override

PARAMETERS

body b2Body
body

b2d.body.reset_mass_data()

b2d.body.reset_mass_data(body:b2Body)

This resets the mass properties to the sum of the mass properties of the shapes. This normally does not need to be called unless you called SetMassData to override

PARAMETERS

body b2Body
body

b2d.body.set_active()

b2d.body.set_active(body:b2Body, enable:boolean)

Set the active state of the body. An inactive body is not simulated and cannot be collided with or woken up. If you pass a flag of true, all fixtures will be added to the broad-phase. If you pass a flag of false, all fixtures will be removed from the broad-phase and all contacts will be destroyed. Fixtures and joints are otherwise unaffected. You may continue to create/destroy fixtures and joints on inactive bodies. Fixtures on an inactive body are implicitly inactive and will not participate in collisions, ray-casts, or queries. Joints connected to an inactive body are implicitly inactive. An inactive body is still owned by a b2World object and remains in the body list.

PARAMETERS

body b2Body
body
enable boolean
true if the body should be active

b2d.body.set_active()

b2d.body.set_active(body:b2Body, enable:boolean)

Set the active state of the body. An inactive body is not simulated and cannot be collided with or woken up. If you pass a flag of true, all shapes will be added to the broad-phase. If you pass a flag of false, all shapes will be removed from the broad-phase and all contacts will be destroyed. Shapes and joints are otherwise unaffected. You may continue to create/destroy shapes and joints on inactive bodies. Shapes on an inactive body are implicitly inactive and will not participate in collisions, ray-casts, or queries. Joints connected to an inactive body are implicitly inactive. An inactive body is still owned by a b2World object and remains in the body list.

PARAMETERS

body b2Body
body
enable boolean
true if the body should be active

b2d.body.set_angular_damping()

b2d.body.set_angular_damping(body:b2Body, damping:number)

Set the angular damping of the body.

PARAMETERS

body b2Body
body
damping number
the damping

b2d.body.set_angular_damping()

b2d.body.set_angular_damping(body:b2Body, damping:number)

Set the angular damping of the body.

PARAMETERS

body b2Body
body
damping number
the damping

b2d.body.set_angular_velocity()

b2d.body.set_angular_velocity(body:b2Body, omega:number)

Set the angular velocity.

PARAMETERS

body b2Body
body
omega number
the new angular velocity in radians/second.

b2d.body.set_angular_velocity()

b2d.body.set_angular_velocity(body:b2Body, omega:number)

Set the angular velocity.

PARAMETERS

body b2Body
body
omega number
the new angular velocity in radians/second.

b2d.body.set_awake()

b2d.body.set_awake(body:b2Body, enable:boolean)

Set the sleep state of the body. A sleeping body has very low CPU cost.

PARAMETERS

body b2Body
body
enable boolean
flag set to false to put body to sleep, true to wake it.

b2d.body.set_awake()

b2d.body.set_awake(body:b2Body, enable:boolean)

Set the sleep state of the body. A sleeping body has very low CPU cost.

PARAMETERS

body b2Body
body
enable boolean
flag set to false to put body to sleep, true to wake it.

b2d.body.set_bullet()

b2d.body.set_bullet(body:b2Body, enable:boolean)

Should this body be treated like a bullet for continuous collision detection?

PARAMETERS

body b2Body
body
enable boolean
if true, the body will be in bullet mode

b2d.body.set_bullet()

b2d.body.set_bullet(body:b2Body, enable:boolean)

Should this body be treated like a bullet for continuous collision detection?

PARAMETERS

body b2Body
body
enable boolean
if true, the body will be in bullet mode

b2d.body.set_fixed_rotation()

b2d.body.set_fixed_rotation(body:b2Body, enable:boolean)

Set this body to have fixed rotation. This causes the mass to be reset.

PARAMETERS

body b2Body
body
enable boolean
true if the rotation should be fixed

b2d.body.set_fixed_rotation()

b2d.body.set_fixed_rotation(body:b2Body, enable:boolean)

Set this body to have fixed rotation. This causes the mass to be reset.

PARAMETERS

body b2Body
body
enable boolean
true if the rotation should be fixed

b2d.body.set_gravity_scale()

b2d.body.set_gravity_scale(body:b2Body, scale:number)

Set the gravity scale of the body.

PARAMETERS

body b2Body
body
scale number
the scale

b2d.body.set_gravity_scale()

b2d.body.set_gravity_scale(body:b2Body, scale:number)

Set the gravity scale of the body.

PARAMETERS

body b2Body
body
scale number
the scale

b2d.body.set_linear_damping()

b2d.body.set_linear_damping(body:b2Body, damping:number)

Set the linear damping of the body.

PARAMETERS

body b2Body
body
damping number
the damping

b2d.body.set_linear_damping()

b2d.body.set_linear_damping(body:b2Body, damping:number)

Set the linear damping of the body.

PARAMETERS

body b2Body
body
damping number
the damping

b2d.body.set_linear_velocity()

b2d.body.set_linear_velocity(body:b2Body, velocity:vector3)

Set the linear velocity of the center of mass.

PARAMETERS

body b2Body
body
velocity vector3
the new linear velocity of the center of mass.

b2d.body.set_linear_velocity()

b2d.body.set_linear_velocity(body:b2Body, velocity:vector3)

Set the linear velocity of the center of mass.

PARAMETERS

body b2Body
body
velocity vector3
the new linear velocity of the center of mass.

b2d.body.set_mass_data()

b2d.body.set_mass_data(body:b2Body, data:b2d.mass_data)

Set the mass properties to override the mass properties of the fixtures.

PARAMETERS

body b2Body
body
data b2d.mass_data
the mass data

b2d.body.set_mass_data()

b2d.body.set_mass_data(body:b2Body, data:b2MassData)

Set the mass properties to override the mass properties of the shapes.

PARAMETERS

body b2Body
body
data b2MassData
the mass properties.

b2d.body.set_name()

b2d.body.set_name(body:b2Body, name:string)

Set the body name.

PARAMETERS

body b2Body
body
name string
body name

b2d.body.set_sleep_threshold()

b2d.body.set_sleep_threshold(body:b2Body, threshold:number)

Set the sleep velocity threshold.

PARAMETERS

body b2Body
body
threshold number
velocity threshold in Defold units per second

b2d.body.set_sleeping_allowed()

b2d.body.set_sleeping_allowed(body:b2Body, enable:boolean)

You can disable sleeping on this body. If you disable sleeping, the body will be woken.

PARAMETERS

body b2Body
body
enable boolean
if false, the body will never sleep, and consume more CPU

b2d.body.set_target_transform()

b2d.body.set_target_transform(body:b2Body, position:vector3, angle:number, time_step:number)

Set velocity to reach a target transform.

PARAMETERS

body b2Body
body
position vector3
target world position
angle number
target world angle in radians
time_step number
time step used to compute velocity

b2d.body.set_transform()

b2d.body.set_transform(body:b2Body, position:vector3, angle:number)

Set the position of the body's origin and rotation. This breaks any contacts and wakes the other bodies. Manipulating a body's transform may cause non-physical behavior.

PARAMETERS

body b2Body
body
position vector3
the world position of the body's local origin.
angle number
the world position of the body's local origin.

b2d.body.set_transform()

b2d.body.set_transform(body:b2Body, position:vector3, angle:number)

Set the position of the body's origin and rotation. This breaks any contacts and wakes the other bodies. Manipulating a body's transform may cause non-physical behavior.

PARAMETERS

body b2Body
body
position vector3
the world position of the body's local origin.
angle number
the world position of the body's local origin.

b2d.body.set_type()

b2d.body.set_type(body:b2Body, type:b2BodyType)

Set the type of this body. This may alter the mass and velocity.

PARAMETERS

body b2Body
body
type b2BodyType
the body type

b2d.body.set_type()

b2d.body.set_type(body:b2Body, type:b2BodyType)

Set the type of this body. This may alter the mass and velocity.

PARAMETERS

body b2Body
body
type b2BodyType
the body type

b2d.body.set_user_data()

b2d.body.set_user_data(body:b2Body, id:hash)

Set the user data. Use this to store your application specific data.

PARAMETERS

body b2Body
body
id hash
the game object id