b2d.body
Functions for interacting with Box2D bodies.
Functions
b2d.body.apply_angular_impulse(body:Opaque<"b2Body">, impulse: number): voidb2d.body.apply_force(body:Opaque<"b2Body">, force: Vector3, point: Vector3): voidb2d.body.apply_force_to_center(body:Opaque<"b2Body">, force: Vector3): voidb2d.body.apply_linear_impulse(body:Opaque<"b2Body">, impulse: Vector3, point: Vector3): voidb2d.body.apply_linear_impulse_to_center(body:Opaque<"b2Body">, impulse: Vector3): voidNb2d.body.apply_torque(body:Opaque<"b2Body">, torque: number): voidb2d.body.compute_aabb(body:Opaque<"b2Body">):b2d.AabbNb2d.body.create_chain(body:Opaque<"b2Body">, definition:b2d.ChainDefinition): LuaMultiReturn<[Opaque<"b2Chain">,b2d.ShapeInfo[]]>Nb2d.body.create_fixture(body:Opaque<"b2Body">, definition: { shape: { type: typeof b2d.shape.SHAPE_TYPE_POLYGON | typeof b2d.shape.SHAPE_TYPE_BOX; hx: number; hy: number; center?: Vector3; angle?: number } | { type: typeof b2d.shape.SHAPE_TYPE_POLYGON | typeof b2d.shape.SHAPE_TYPE_BOX; vertices: Vector3[] } | { type: typeof b2d.shape.SHAPE_TYPE_CIRCLE; radius: number; center?: Vector3 } | { type: typeof b2d.shape.SHAPE_TYPE_EDGE; v1: Vector3; v2: Vector3; v0?: Vector3; v3?: Vector3 } | { type: typeof b2d.shape.SHAPE_TYPE_CHAIN; vertices: Vector3[]; loop?: boolean; prev_vertex?: Vector3; next_vertex?: Vector3 }; friction?: number; restitution?: number; density?: number; sensor?: boolean; is_sensor?: boolean; filter?: { category_bits: number; mask_bits: number; group_index: number } }):b2d.FixtureInfoNb2d.body.create_shape(body:Opaque<"b2Body">, definition: ({ shape: { type: typeof b2d.shape.SHAPE_TYPE_POLYGON | typeof b2d.shape.SHAPE_TYPE_BOX; hx: number; hy: number; center?: Vector3; angle?: number } | { type: typeof b2d.shape.SHAPE_TYPE_POLYGON | typeof b2d.shape.SHAPE_TYPE_BOX; vertices: Vector3[] } | { type: typeof b2d.shape.SHAPE_TYPE_CIRCLE; radius: number; center?: Vector3 } | { type: typeof b2d.shape.SHAPE_TYPE_CAPSULE; radius: number; center1: Vector3; center2: Vector3 } | { type: typeof b2d.shape.SHAPE_TYPE_EDGE | typeof b2d.shape.SHAPE_TYPE_SEGMENT; v1: Vector3; v2: Vector3 } } | { type: typeof b2d.shape.SHAPE_TYPE_POLYGON | typeof b2d.shape.SHAPE_TYPE_BOX; hx: number; hy: number; center?: Vector3; angle?: number } | { type: typeof b2d.shape.SHAPE_TYPE_POLYGON | typeof b2d.shape.SHAPE_TYPE_BOX; vertices: Vector3[] } | { type: typeof b2d.shape.SHAPE_TYPE_CIRCLE; radius: number; center?: Vector3 } | { type: typeof b2d.shape.SHAPE_TYPE_CAPSULE; radius: number; center1: Vector3; center2: Vector3 } | { type: typeof b2d.shape.SHAPE_TYPE_EDGE | typeof b2d.shape.SHAPE_TYPE_SEGMENT; v1: Vector3; v2: Vector3 }) & { density?: number; friction?: number; restitution?: number; material?: number; sensor?: boolean; is_sensor?: boolean; filter?: { category_bits: number; mask_bits: number; group_index: number } }): { index: number; shape_id:Opaque<"b2Shape">; type: number; sensor: boolean; density: number; friction: number; restitution: number; material: number; child_count: number; is_chain_segment: boolean }Nb2d.body.destroy_fixture(body:Opaque<"b2Body">, fixture_index: number): voidNb2d.body.destroy_shape(body:Opaque<"b2Body">, shape_index: number): voidNb2d.body.dump(body:Opaque<"b2Body">): voidNb2d.body.enable_contact_events(body:Opaque<"b2Body">, enable: boolean): voidNb2d.body.enable_hit_events(body:Opaque<"b2Body">, enable: boolean): voidNb2d.body.enable_sleep(body:Opaque<"b2Body">, enable: boolean): voidb2d.body.get_angle(body:Opaque<"b2Body">): numberb2d.body.get_angular_damping(body:Opaque<"b2Body">): numberb2d.body.get_angular_velocity(body:Opaque<"b2Body">): numberb2d.body.get_contact_data(body:Opaque<"b2Body">):b2d.ContactData[]Nb2d.body.get_contact_list(body:Opaque<"b2Body">):Opaque<"b2ContactEdge">Cb2d.body.get_fixtures(body:Opaque<"b2Body">):b2d.FixtureInfo[]Nb2d.body.get_force(body:Opaque<"b2Body">): Vector3Nb2d.body.get_gravity_scale(body:Opaque<"b2Body">): numberb2d.body.get_inertia(body:Opaque<"b2Body">): numberNb2d.body.get_joints(body:Opaque<"b2Body">):Opaque<"b2Joint">[]Nb2d.body.get_linear_damping(body:Opaque<"b2Body">): numberb2d.body.get_linear_velocity(body:Opaque<"b2Body">): Vector3b2d.body.get_linear_velocity_from_local_point(body:Opaque<"b2Body">, local_point: Vector3): Vector3b2d.body.get_linear_velocity_from_world_point(body:Opaque<"b2Body">, world_point: Vector3): Vector3b2d.body.get_local_center(body:Opaque<"b2Body">): Vector3Nb2d.body.get_local_center_of_mass(body:Opaque<"b2Body">): Vector3b2d.body.get_local_point(body:Opaque<"b2Body">, world_point: Vector3): Vector3b2d.body.get_local_vector(body:Opaque<"b2Body">, world_vector: Vector3): Vector3b2d.body.get_mass(body:Opaque<"b2Body">): numberb2d.body.get_mass_data(body:Opaque<"b2Body">):b2d.MassDataNb2d.body.get_name(body:Opaque<"b2Body">): string | undefinedNb2d.body.get_next(body:Opaque<"b2Body">):Opaque<"b2Body"> | undefinedNb2d.body.get_position(body:Opaque<"b2Body">): Vector3b2d.body.get_rotational_inertia(body:Opaque<"b2Body">): numberb2d.body.get_shapes(body:Opaque<"b2Body">):b2d.ShapeInfo[]Nb2d.body.get_sleep_threshold(body:Opaque<"b2Body">): numberNb2d.body.get_transform(body:Opaque<"b2Body">):b2d.TransformNb2d.body.get_type(body:Opaque<"b2Body">): (number & { readonly __brand: "b2d.body.B2_DYNAMIC_BODY" }) | (number & { readonly __brand: "b2d.body.B2_KINEMATIC_BODY" }) | (number & { readonly __brand: "b2d.body.B2_STATIC_BODY" })b2d.body.get_user_data(body:Opaque<"b2Body">): HashNb2d.body.get_world(body:Opaque<"b2Body">):Opaque<"b2World">b2d.body.get_world_center(body:Opaque<"b2Body">): Vector3Nb2d.body.get_world_center_of_mass(body:Opaque<"b2Body">): Vector3b2d.body.get_world_point(body:Opaque<"b2Body">, local_vector: Vector3): Vector3b2d.body.get_world_vector(body:Opaque<"b2Body">, local_vector: Vector3): Vector3b2d.body.is_active(body:Opaque<"b2Body">): booleanb2d.body.is_awake(body:Opaque<"b2Body">): booleanb2d.body.is_bullet(body:Opaque<"b2Body">): booleanb2d.body.is_fixed_rotation(body:Opaque<"b2Body">): booleanb2d.body.is_sleeping_allowed(body:Opaque<"b2Body">): booleanNb2d.body.is_sleeping_enabled(body:Opaque<"b2Body">): booleanb2d.body.is_valid(body:Opaque<"b2Body">): booleanNb2d.body.reset_mass_data(body:Opaque<"b2Body">): voidb2d.body.set_active(body:Opaque<"b2Body">, enable: boolean): voidb2d.body.set_angular_damping(body:Opaque<"b2Body">, damping: number): voidb2d.body.set_angular_velocity(body:Opaque<"b2Body">, omega: number): voidb2d.body.set_awake(body:Opaque<"b2Body">, enable: boolean): voidb2d.body.set_bullet(body:Opaque<"b2Body">, enable: boolean): voidb2d.body.set_fixed_rotation(body:Opaque<"b2Body">, enable: boolean): voidb2d.body.set_gravity_scale(body:Opaque<"b2Body">, scale: number): voidb2d.body.set_linear_damping(body:Opaque<"b2Body">, damping: number): voidb2d.body.set_linear_velocity(body:Opaque<"b2Body">, velocity: Vector3): voidb2d.body.set_mass_data(body:Opaque<"b2Body">, data:b2d.MassData): voidNb2d.body.set_name(body:Opaque<"b2Body">, name: string): voidNb2d.body.set_sleep_threshold(body:Opaque<"b2Body">, threshold: number): voidNb2d.body.set_sleeping_allowed(body:Opaque<"b2Body">, enable: boolean): voidNb2d.body.set_target_transform(body:Opaque<"b2Body">, position: Vector3, angle: number, time_step: number): voidNb2d.body.set_transform(body:Opaque<"b2Body">, position: Vector3, angle: number): voidb2d.body.set_type(body:Opaque<"b2Body">, type: (number & { readonly __brand: "b2d.body.B2_DYNAMIC_BODY" }) | (number & { readonly __brand: "b2d.body.B2_KINEMATIC_BODY" }) | (number & { readonly __brand: "b2d.body.B2_STATIC_BODY" })): voidb2d.body.set_user_data(body:Opaque<"b2Body">, id: Hash)N
b2d.body.apply_angular_impulse(body: Opaque<"b2Body">, impulse: number): void
Apply an angular impulse.
Parameters
body:Opaque<"b2Body">— bodyimpulse:number— impulse the angular impulse in units of kgmm/s
b2d.body.apply_force(body: Opaque<"b2Body">, force: Vector3, point: Vector3): void
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:Opaque<"b2Body">— bodyforce: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(body: Opaque<"b2Body">, force: Vector3): void
Apply a force to the center of mass. This wakes up the body.
Parameters
body:Opaque<"b2Body">— bodyforce:Vector3— the world force vector, usually in Newtons (N).
b2d.body.apply_linear_impulse(body: Opaque<"b2Body">, impulse: Vector3, point: Vector3): void
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:Opaque<"b2Body">— bodyimpulse: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(body: Opaque<"b2Body">, impulse: Vector3): voidN
- Since Defold 1.13.0
Apply a linear impulse to the center of mass.
Parameters
body:Opaque<"b2Body">— bodyimpulse:Vector3— world impulse vector
b2d.body.apply_torque(body: Opaque<"b2Body">, torque: number): void
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:Opaque<"b2Body">— bodytorque:number— torque about the z-axis (out of the screen), usually in N-m.
b2d.body.compute_aabb(body: Opaque<"b2Body">): b2d.AabbN
- Since Defold 1.13.0
Compute the world AABB of all body shapes.
Parameters
body:Opaque<"b2Body">— body
Returns
aabb:b2d.Aabb— body bounds
b2d.body.create_chain(body: Opaque<"b2Body">, definition: b2d.ChainDefinition): LuaMultiReturn<[Opaque<"b2Chain">, b2d.ShapeInfo[]]>N
- Since Defold 1.13.0
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.
const body = b2d.get_body("#collisionobject");
if (body !== undefined) {
const [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,
});
}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,
})Parameters
body:Opaque<"b2Body">— bodydefinition:b2d.ChainDefinition— the chain definition
Returns
chain:Opaque<"b2Chain">— created chain handlesegments:b2d.ShapeInfo[]— created chain segments
b2d.body.create_fixture(body: Opaque<"b2Body">, definition: { shape: { type: typeof b2d.shape.SHAPE_TYPE_POLYGON | typeof b2d.shape.SHAPE_TYPE_BOX; hx: number; hy: number; center?: Vector3; angle?: number } | { type: typeof b2d.shape.SHAPE_TYPE_POLYGON | typeof b2d.shape.SHAPE_TYPE_BOX; vertices: Vector3[] } | { type: typeof b2d.shape.SHAPE_TYPE_CIRCLE; radius: number; center?: Vector3 } | { type: typeof b2d.shape.SHAPE_TYPE_EDGE; v1: Vector3; v2: Vector3; v0?: Vector3; v3?: Vector3 } | { type: typeof b2d.shape.SHAPE_TYPE_CHAIN; vertices: Vector3[]; loop?: boolean; prev_vertex?: Vector3; next_vertex?: Vector3 }; friction?: number; restitution?: number; density?: number; sensor?: boolean; is_sensor?: boolean; filter?: { category_bits: number; mask_bits: number; group_index: number } }): b2d.FixtureInfoN
- Since Defold 1.13.0
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.
const body = b2d.get_body("#collisionobject");
if (body !== undefined) {
const 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)] },
});
}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),
},
},
})Parameters
body:Opaque<"b2Body">— bodydefinition:{ shape: { type: typeof b2d.shape.SHAPE_TYPE_POLYGON | typeof b2d.shape.SHAPE_TYPE_BOX; hx: number; hy: number; center?: Vector3; angle?: number } | { type: typeof b2d.shape.SHAPE_TYPE_POLYGON | typeof b2d.shape.SHAPE_TYPE_BOX; vertices: Vector3[] } | { type: typeof b2d.shape.SHAPE_TYPE_CIRCLE; radius: number; center?: Vector3 } | { type: typeof b2d.shape.SHAPE_TYPE_EDGE; v1: Vector3; v2: Vector3; v0?: Vector3; v3?: Vector3 } | { type: typeof b2d.shape.SHAPE_TYPE_CHAIN; vertices: Vector3[]; loop?: boolean; prev_vertex?: Vector3; next_vertex?: Vector3 }; friction?: number; restitution?: number; density?: number; sensor?: boolean; is_sensor?: boolean; filter?: { category_bits: number; mask_bits: number; group_index: number } }— fixture definition
Returns
fixture:b2d.FixtureInfo— fixture information. ⚠️indexis 1-based; passed to Defold unchanged.
b2d.body.create_shape(body: Opaque<"b2Body">, definition: ({ shape: { type: typeof b2d.shape.SHAPE_TYPE_POLYGON | typeof b2d.shape.SHAPE_TYPE_BOX; hx: number; hy: number; center?: Vector3; angle?: number } | { type: typeof b2d.shape.SHAPE_TYPE_POLYGON | typeof b2d.shape.SHAPE_TYPE_BOX; vertices: Vector3[] } | { type: typeof b2d.shape.SHAPE_TYPE_CIRCLE; radius: number; center?: Vector3 } | { type: typeof b2d.shape.SHAPE_TYPE_CAPSULE; radius: number; center1: Vector3; center2: Vector3 } | { type: typeof b2d.shape.SHAPE_TYPE_EDGE | typeof b2d.shape.SHAPE_TYPE_SEGMENT; v1: Vector3; v2: Vector3 } } | { type: typeof b2d.shape.SHAPE_TYPE_POLYGON | typeof b2d.shape.SHAPE_TYPE_BOX; hx: number; hy: number; center?: Vector3; angle?: number } | { type: typeof b2d.shape.SHAPE_TYPE_POLYGON | typeof b2d.shape.SHAPE_TYPE_BOX; vertices: Vector3[] } | { type: typeof b2d.shape.SHAPE_TYPE_CIRCLE; radius: number; center?: Vector3 } | { type: typeof b2d.shape.SHAPE_TYPE_CAPSULE; radius: number; center1: Vector3; center2: Vector3 } | { type: typeof b2d.shape.SHAPE_TYPE_EDGE | typeof b2d.shape.SHAPE_TYPE_SEGMENT; v1: Vector3; v2: Vector3 }) & { density?: number; friction?: number; restitution?: number; material?: number; sensor?: boolean; is_sensor?: boolean; filter?: { category_bits: number; mask_bits: number; group_index: number } }): { index: number; shape_id: Opaque<"b2Shape">; type: number; sensor: boolean; density: number; friction: number; restitution: number; material: number; child_count: number; is_chain_segment: boolean }N
- Since Defold 1.13.0
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:Opaque<"b2Body">— bodydefinition:({ shape: { type: typeof b2d.shape.SHAPE_TYPE_POLYGON | typeof b2d.shape.SHAPE_TYPE_BOX; hx: number; hy: number; center?: Vector3; angle?: number } | { type: typeof b2d.shape.SHAPE_TYPE_POLYGON | typeof b2d.shape.SHAPE_TYPE_BOX; vertices: Vector3[] } | { type: typeof b2d.shape.SHAPE_TYPE_CIRCLE; radius: number; center?: Vector3 } | { type: typeof b2d.shape.SHAPE_TYPE_CAPSULE; radius: number; center1: Vector3; center2: Vector3 } | { type: typeof b2d.shape.SHAPE_TYPE_EDGE | typeof b2d.shape.SHAPE_TYPE_SEGMENT; v1: Vector3; v2: Vector3 } } | { type: typeof b2d.shape.SHAPE_TYPE_POLYGON | typeof b2d.shape.SHAPE_TYPE_BOX; hx: number; hy: number; center?: Vector3; angle?: number } | { type: typeof b2d.shape.SHAPE_TYPE_POLYGON | typeof b2d.shape.SHAPE_TYPE_BOX; vertices: Vector3[] } | { type: typeof b2d.shape.SHAPE_TYPE_CIRCLE; radius: number; center?: Vector3 } | { type: typeof b2d.shape.SHAPE_TYPE_CAPSULE; radius: number; center1: Vector3; center2: Vector3 } | { type: typeof b2d.shape.SHAPE_TYPE_EDGE | typeof b2d.shape.SHAPE_TYPE_SEGMENT; v1: Vector3; v2: Vector3 }) & { density?: number; friction?: number; restitution?: number; material?: number; sensor?: boolean; is_sensor?: boolean; filter?: { category_bits: number; mask_bits: number; group_index: number } }— the shape definition.
b2d.body.destroy_fixture(body: Opaque<"b2Body">, fixture_index: number): voidN
- Since Defold 1.13.0
Destroy a fixture from a body.
Parameters
body:Opaque<"b2Body">— bodyfixture_index:number— 1-based fixture index from b2d.body.get_fixtures. ⚠️ 1-based; passed to Defold unchanged.
b2d.body.destroy_shape(body: Opaque<"b2Body">, shape_index: number): voidN
- Since Defold 1.13.0
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:Opaque<"b2Body">— bodyshape_index:number— 1-based shape index fromb2d.body.get_shapes. ⚠️ 1-based; passed to Defold unchanged.
b2d.body.dump(body: Opaque<"b2Body">): voidN
- Since Defold 1.13.0
Print the body representation to the log output
Parameters
body:Opaque<"b2Body">— body
b2d.body.enable_contact_events(body: Opaque<"b2Body">, enable: boolean): voidN
- Since Defold 1.13.0
Enable or disable contact events on all body shapes.
Parameters
body:Opaque<"b2Body">— bodyenable:boolean— true to enable contact events
b2d.body.enable_hit_events(body: Opaque<"b2Body">, enable: boolean): voidN
- Since Defold 1.13.0
Enable or disable hit events on all body shapes.
Parameters
body:Opaque<"b2Body">— bodyenable:boolean— true to enable hit events
b2d.body.enable_sleep(body: Opaque<"b2Body">, enable: boolean): void
You can disable sleeping on this body. If you disable sleeping, the body will be woken.
Parameters
body:Opaque<"b2Body">— bodyenable:boolean— if false, the body will never sleep, and consume more CPU
b2d.body.get_angle(body: Opaque<"b2Body">): number
Get the angle in radians.
Parameters
body:Opaque<"b2Body">— body
Returns
angle:number— the current world rotation angle in radians.
b2d.body.get_angular_damping(body: Opaque<"b2Body">): number
Get the angular damping of the body.
Parameters
body:Opaque<"b2Body">— body
Returns
damping:number— the damping
b2d.body.get_angular_velocity(body: Opaque<"b2Body">): number
Get the angular velocity.
Parameters
body:Opaque<"b2Body">— body
Returns
velocity:number— the angular velocity in radians/second.
b2d.body.get_contact_data(body: Opaque<"b2Body">): b2d.ContactData[]N
- Since Defold 1.13.0
Get touching contact data for a body.
Parameters
body:Opaque<"b2Body">— body
Returns
contacts:b2d.ContactData[]— array of contact tables
b2d.body.get_contact_list(body: Opaque<"b2Body">): Opaque<"b2ContactEdge">C
- Available in Defold 1.13.0–1.13.1
Get the list of all contacts attached to this body.
Parameters
body:Opaque<"b2Body">— body
Returns
edge:Opaque<"b2ContactEdge">— the first edge
b2d.body.get_fixtures(body: Opaque<"b2Body">): b2d.FixtureInfo[]N
- Since Defold 1.13.0
Get the fixtures attached to this body.
Parameters
body:Opaque<"b2Body">— body
Returns
fixtures:b2d.FixtureInfo[]— the attached fixtures. ⚠️indexis 1-based; passed to Defold unchanged.
b2d.body.get_force(body: Opaque<"b2Body">): Vector3N
- Since Defold 1.13.0
Get the total force currently applied on this object
Parameters
body:Opaque<"b2Body">— body
Returns
force:Vector3
b2d.body.get_gravity_scale(body: Opaque<"b2Body">): number
Get the gravity scale of the body.
Parameters
body:Opaque<"b2Body">— body
Returns
scale:number— the scale
b2d.body.get_inertia(body: Opaque<"b2Body">): numberN
- Since Defold 1.13.0
Get the rotational inertia of the body about the local origin.
Parameters
body:Opaque<"b2Body">— body
Returns
inertia:number— the rotational inertia, usually in kg-m^2.
b2d.body.get_joints(body: Opaque<"b2Body">): Opaque<"b2Joint">[]N
- Since Defold 1.13.0
Get the joints attached to this body.
Parameters
body:Opaque<"b2Body">— body
Returns
joints:Opaque<"b2Joint">[]— joint handles created by b2d.joint
b2d.body.get_linear_damping(body: Opaque<"b2Body">): number
Get the linear damping of the body.
Parameters
body:Opaque<"b2Body">— body
Returns
damping:number— the damping
b2d.body.get_linear_velocity(body: Opaque<"b2Body">): Vector3
Get the linear velocity of the center of mass.
Parameters
body:Opaque<"b2Body">— body
Returns
velocity:Vector3— the linear velocity of the center of mass.
b2d.body.get_linear_velocity_from_local_point(body: Opaque<"b2Body">, local_point: Vector3): Vector3
Get the world velocity of a local point.
Parameters
body:Opaque<"b2Body">— bodylocal_point:Vector3— a point in local coordinates.
Returns
velocity:Vector3— the world velocity of a point.
b2d.body.get_linear_velocity_from_world_point(body: Opaque<"b2Body">, world_point: Vector3): Vector3
Get the world linear velocity of a world point attached to this body.
Parameters
body:Opaque<"b2Body">— bodyworld_point:Vector3— a point in world coordinates.
Returns
velocity:Vector3— the world velocity of a point.
b2d.body.get_local_center(body: Opaque<"b2Body">): Vector3N
- Since Defold 1.13.0
Get the local position of the center of mass.
Parameters
body:Opaque<"b2Body">— body
Returns
center:Vector3— Get the local position of the center of mass.
b2d.body.get_local_center_of_mass(body: Opaque<"b2Body">): Vector3
Get the local position of the center of mass.
Parameters
body:Opaque<"b2Body">— body
Returns
center:Vector3— Get the local position of the center of mass.
b2d.body.get_local_point(body: Opaque<"b2Body">, world_point: Vector3): Vector3
Gets a local point relative to the body's origin given a world point.
Parameters
body:Opaque<"b2Body">— bodyworld_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(body: Opaque<"b2Body">, world_vector: Vector3): Vector3
Gets a local vector given a world vector.
Parameters
body:Opaque<"b2Body">— bodyworld_vector:Vector3— a vector in world coordinates.
Returns
vector:Vector3— the corresponding local vector.
b2d.body.get_mass(body: Opaque<"b2Body">): number
Get the total mass of the body.
Parameters
body:Opaque<"b2Body">— body
Returns
mass:number— the mass, usually in kilograms (kg).
b2d.body.get_mass_data(body: Opaque<"b2Body">): b2d.MassDataN
- Since Defold 1.13.0
Get the mass data of the body.
Parameters
body:Opaque<"b2Body">— body
Returns
data:b2d.MassData— the mass data
b2d.body.get_name(body: Opaque<"b2Body">): string | undefinedN
- Since Defold 1.13.0
Signature changed in Defold 1.13.2 — before:
(body: Opaque<"b2Body">): string
Get the body name.
Parameters
body:Opaque<"b2Body">— body
Returns
name:string | undefined— body name, ornilif no name is set
b2d.body.get_next(body: Opaque<"b2Body">): Opaque<"b2Body"> | undefinedN
- Since Defold 1.13.0
Signature changed in Defold 1.13.2 — before:
(body: Opaque<"b2Body">): Opaque<"b2Body">
Get the next body in the world's body list.
Parameters
body:Opaque<"b2Body">— body
Returns
body:Opaque<"b2Body"> | undefined— the next body, ornilif this is the last body
b2d.body.get_position(body: Opaque<"b2Body">): Vector3
Get the world body origin position.
Parameters
body:Opaque<"b2Body">— body
Returns
position:Vector3— the world position of the body's origin.
b2d.body.get_rotational_inertia(body: Opaque<"b2Body">): number
Get the rotational inertia of the body about the local origin.
Parameters
body:Opaque<"b2Body">— body
Returns
inertia:number— the rotational inertia, usually in kg-m^2.
b2d.body.get_shapes(body: Opaque<"b2Body">): b2d.ShapeInfo[]N
- Since Defold 1.13.0
Get the list of all shapes attached to this body.
Parameters
body:Opaque<"b2Body">— body
Returns
shapes:b2d.ShapeInfo[]— attached shapes
b2d.body.get_sleep_threshold(body: Opaque<"b2Body">): numberN
- Since Defold 1.13.0
Get the sleep velocity threshold.
Parameters
body:Opaque<"b2Body">— body
Returns
threshold:number— velocity threshold in Defold units per second
b2d.body.get_transform(body: Opaque<"b2Body">): b2d.TransformN
- Since Defold 1.13.0
Get the body transform for the body's origin.
Parameters
body:Opaque<"b2Body">— body
Returns
transform:b2d.Transform— the body transform
b2d.body.get_type(body: Opaque<"b2Body">): (number & { readonly __brand: "b2d.body.B2_DYNAMIC_BODY" }) | (number & { readonly __brand: "b2d.body.B2_KINEMATIC_BODY" }) | (number & { readonly __brand: "b2d.body.B2_STATIC_BODY" })
Get the type of this body.
Parameters
body:Opaque<"b2Body">— body
Returns
type:(number & { readonly __brand: "b2d.body.B2_DYNAMIC_BODY" }) | (number & { readonly __brand: "b2d.body.B2_KINEMATIC_BODY" }) | (number & { readonly __brand: "b2d.body.B2_STATIC_BODY" })— the body type
b2d.body.get_user_data(body: Opaque<"b2Body">): HashN
- Since Defold 1.13.0
Get the user data pointer that was provided in the body definition.
Parameters
body:Opaque<"b2Body">— body
Returns
id:Hash— the game object id this body is connected to
b2d.body.get_world(body: Opaque<"b2Body">): Opaque<"b2World">
Get the parent world of this body.
Parameters
body:Opaque<"b2Body">— body
Returns
world:Opaque<"b2World">
b2d.body.get_world_center(body: Opaque<"b2Body">): Vector3N
- 1 overload removed in Defold 1.13.2
- Since Defold 1.13.0
Removed in Defold 1.13.2:
(body: Opaque<"b2Body">): number
Get the world position of the center of mass.
Parameters
body:Opaque<"b2Body">— body
Returns
center:Vector3— Get the world position of the center of mass.
b2d.body.get_world_center_of_mass(body: Opaque<"b2Body">): Vector3
Get the world position of the center of mass.
Parameters
body:Opaque<"b2Body">— body
Returns
center:Vector3— Get the world position of the center of mass.
b2d.body.get_world_point(body: Opaque<"b2Body">, local_vector: Vector3): Vector3
Get the world coordinates of a point given the local coordinates.
Parameters
body:Opaque<"b2Body">— bodylocal_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(body: Opaque<"b2Body">, local_vector: Vector3): Vector3
Get the world coordinates of a vector given the local coordinates.
Parameters
body:Opaque<"b2Body">— bodylocal_vector:Vector3— a vector fixed in the body.
Returns
vector:Vector3— the same vector expressed in world coordinates.
b2d.body.is_active(body: Opaque<"b2Body">): boolean
Get the active state of the body.
Parameters
body:Opaque<"b2Body">— body
Returns
enabled:boolean— is the body active
b2d.body.is_awake(body: Opaque<"b2Body">): boolean
Get the sleeping state of this body.
Parameters
body:Opaque<"b2Body">— body
Returns
enabled:boolean— true if the body is awake, false if it's sleeping.
b2d.body.is_bullet(body: Opaque<"b2Body">): boolean
Is this body in bullet mode
Parameters
body:Opaque<"b2Body">— body
Returns
enabled:boolean— true if the body is in bullet mode
b2d.body.is_fixed_rotation(body: Opaque<"b2Body">): boolean
Does this body have fixed rotation?
Parameters
body:Opaque<"b2Body">— body
Returns
enabled:boolean— is the rotation fixed
b2d.body.is_sleeping_allowed(body: Opaque<"b2Body">): booleanN
- Since Defold 1.13.0
Is this body allowed to sleep
Parameters
body:Opaque<"b2Body">— body
Returns
enabled:boolean— true if the body is allowed to sleep
b2d.body.is_sleeping_enabled(body: Opaque<"b2Body">): boolean
Is this body allowed to sleep
Parameters
body:Opaque<"b2Body">— body
Returns
enabled:boolean— true if the body is allowed to sleep
b2d.body.is_valid(body: Opaque<"b2Body">): booleanN
- Since Defold 1.13.0
Validate a body handle.
Parameters
body:Opaque<"b2Body">— body
Returns
valid:boolean— true if the body handle still refers to a live Box2D body
b2d.body.reset_mass_data(body: Opaque<"b2Body">): void
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:Opaque<"b2Body">— body
b2d.body.set_active(body: Opaque<"b2Body">, enable: boolean): void
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:Opaque<"b2Body">— bodyenable:boolean— true if the body should be active
b2d.body.set_angular_damping(body: Opaque<"b2Body">, damping: number): void
Set the angular damping of the body.
Parameters
body:Opaque<"b2Body">— bodydamping:number— the damping
b2d.body.set_angular_velocity(body: Opaque<"b2Body">, omega: number): void
Set the angular velocity.
Parameters
body:Opaque<"b2Body">— bodyomega:number— the new angular velocity in radians/second.
b2d.body.set_awake(body: Opaque<"b2Body">, enable: boolean): void
Set the sleep state of the body. A sleeping body has very low CPU cost.
Parameters
body:Opaque<"b2Body">— bodyenable:boolean— flag set to false to put body to sleep, true to wake it.
b2d.body.set_bullet(body: Opaque<"b2Body">, enable: boolean): void
Should this body be treated like a bullet for continuous collision detection?
Parameters
body:Opaque<"b2Body">— bodyenable:boolean— if true, the body will be in bullet mode
b2d.body.set_fixed_rotation(body: Opaque<"b2Body">, enable: boolean): void
Set this body to have fixed rotation. This causes the mass to be reset.
Parameters
body:Opaque<"b2Body">— bodyenable:boolean— true if the rotation should be fixed
b2d.body.set_gravity_scale(body: Opaque<"b2Body">, scale: number): void
Set the gravity scale of the body.
Parameters
body:Opaque<"b2Body">— bodyscale:number— the scale
b2d.body.set_linear_damping(body: Opaque<"b2Body">, damping: number): void
Set the linear damping of the body.
Parameters
body:Opaque<"b2Body">— bodydamping:number— the damping
b2d.body.set_linear_velocity(body: Opaque<"b2Body">, velocity: Vector3): void
Set the linear velocity of the center of mass.
Parameters
body:Opaque<"b2Body">— bodyvelocity:Vector3— the new linear velocity of the center of mass.
b2d.body.set_mass_data(body: Opaque<"b2Body">, data: b2d.MassData): voidN
- Since Defold 1.13.0
Set the mass properties to override the mass properties of the fixtures.
Parameters
body:Opaque<"b2Body">— bodydata:b2d.MassData— the mass data
b2d.body.set_name(body: Opaque<"b2Body">, name: string): voidN
- Since Defold 1.13.0
Set the body name.
Parameters
body:Opaque<"b2Body">— bodyname:string— body name
b2d.body.set_sleep_threshold(body: Opaque<"b2Body">, threshold: number): voidN
- Since Defold 1.13.0
Set the sleep velocity threshold.
Parameters
body:Opaque<"b2Body">— bodythreshold:number— velocity threshold in Defold units per second
b2d.body.set_sleeping_allowed(body: Opaque<"b2Body">, enable: boolean): voidN
- Since Defold 1.13.0
You can disable sleeping on this body. If you disable sleeping, the body will be woken.
Parameters
body:Opaque<"b2Body">— bodyenable:boolean— if false, the body will never sleep, and consume more CPU
b2d.body.set_target_transform(body: Opaque<"b2Body">, position: Vector3, angle: number, time_step: number): voidN
- Since Defold 1.13.0
Set velocity to reach a target transform.
Parameters
body:Opaque<"b2Body">— bodyposition:Vector3— target world positionangle:number— target world angle in radianstime_step:number— time step used to compute velocity
b2d.body.set_transform(body: Opaque<"b2Body">, position: Vector3, angle: number): void
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:Opaque<"b2Body">— bodyposition: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(body: Opaque<"b2Body">, type: (number & { readonly __brand: "b2d.body.B2_DYNAMIC_BODY" }) | (number & { readonly __brand: "b2d.body.B2_KINEMATIC_BODY" }) | (number & { readonly __brand: "b2d.body.B2_STATIC_BODY" })): void
Set the type of this body. This may alter the mass and velocity.
Parameters
body:Opaque<"b2Body">— bodytype:(number & { readonly __brand: "b2d.body.B2_DYNAMIC_BODY" }) | (number & { readonly __brand: "b2d.body.B2_KINEMATIC_BODY" }) | (number & { readonly __brand: "b2d.body.B2_STATIC_BODY" })— the body type
b2d.body.set_user_data(body: Opaque<"b2Body">, id: Hash)N
- Since Defold 1.13.0
Set the user data. Use this to store your application specific data.
Parameters
body:Opaque<"b2Body">— bodyid:Hash— the game object id
Constants
b2d.body.B2_DYNAMIC_BODY: number & { readonly __brand: "b2d.body.B2_DYNAMIC_BODY" }
Dynamic body
b2d.body.B2_KINEMATIC_BODY: number & { readonly __brand: "b2d.body.B2_KINEMATIC_BODY" }
Kinematic body
b2d.body.B2_STATIC_BODY: number & { readonly __brand: "b2d.body.B2_STATIC_BODY" }
Static (immovable) body