Box2D b2Body documentation

Version: beta

FUNCTIONS
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_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_torque() Apply a torque. This affects the angular velocity ...
b2d.body.dump() Print the body representation to the log output
b2d.body.get_angular_damping() Get the angular damping of the body.
b2d.body.get_angular_velocity() Get the angular velocity.
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_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_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_local_center() 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_vector() Gets a local vector given a world vector.
b2d.body.get_mass() Get the total mass of the body.
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_type() Get the type of this body.
b2d.body.get_world() Get the parent world of this body.
b2d.body.get_world_center() Get the angle in radians.
b2d.body.get_world_center() 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_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_awake() Get the sleeping state of this body.
b2d.body.is_bullet() Is this body in bullet mode
b2d.body.is_fixed_rotation() Does this body have fixed rotation?
b2d.body.is_sleeping_allowed() Is this body allowed to sleep
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_angular_damping() Set the angular damping of the body.
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_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_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_velocity() Set the linear velocity of the center of mass.
b2d.body.set_sleeping_allowed() You can disable sleeping on this body. If you disable sleeping, the body will be woken.
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.
CONSTANTS
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,impulse)

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,force,point)

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,force)

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,impulse,point)

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_torque()

b2d.body.apply_torque(body,torque)

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.dump()

b2d.body.dump(body)

Print the body representation to the log output

PARAMETERS

body b2Body body

b2d.body.get_angular_damping()

b2d.body.get_angular_damping(body)

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)

Get the angular velocity.

PARAMETERS

body b2Body body

RETURNS

velocity number the angular velocity in radians/second.

b2d.body.get_gravity_scale()

b2d.body.get_gravity_scale(body)

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)

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_linear_damping()

b2d.body.get_linear_damping(body)

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)

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,local_point)

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,world_point)

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)

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,world_point)

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,world_vector)

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)

Get the total mass of the body.

PARAMETERS

body b2Body body

RETURNS

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

b2d.body.get_next()

b2d.body.get_next(body)

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

PARAMETERS

body b2Body body

RETURNS

body b2Body the next body

b2d.body.get_position()

b2d.body.get_position(body)

Get the world body origin position.

PARAMETERS

body b2Body body

RETURNS

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

b2d.body.get_type()

b2d.body.get_type(body)

Get the type of this body.

PARAMETERS

body b2Body body

RETURNS

type b2BodyType the body type

b2d.body.get_world()

b2d.body.get_world(body)

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)

Get the angle in radians.

PARAMETERS

body b2Body body

RETURNS

angle number the current world rotation angle in radians.

b2d.body.get_world_center()

b2d.body.get_world_center(body)

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,local_vector)

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,local_vector)

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)

Get the active state of the body.

PARAMETERS

body b2Body body

RETURNS

enabled bool is the body active

b2d.body.is_awake()

b2d.body.is_awake(body)

Get the sleeping state of this body.

PARAMETERS

body b2Body body

RETURNS

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

b2d.body.is_bullet()

b2d.body.is_bullet(body)

Is this body in bullet mode

PARAMETERS

body b2Body body

RETURNS

enabled bool true if the body is in bullet mode

b2d.body.is_fixed_rotation()

b2d.body.is_fixed_rotation(body)

Does this body have fixed rotation?

PARAMETERS

body b2Body body

RETURNS

enabled bool is the rotation fixed

b2d.body.is_sleeping_allowed()

b2d.body.is_sleeping_allowed(body)

Is this body allowed to sleep

PARAMETERS

body b2Body body

RETURNS

enabled bool true if the body is allowed to sleep

b2d.body.reset_mass_data()

b2d.body.reset_mass_data(body)

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.set_active()

b2d.body.set_active(body,enable)

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 bool true if the body should be active

b2d.body.set_angular_damping()

b2d.body.set_angular_damping(body,damping)

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,omega)

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,enable)

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

PARAMETERS

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

b2d.body.set_bullet()

b2d.body.set_bullet(body,enable)

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

PARAMETERS

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

b2d.body.set_fixed_rotation()

b2d.body.set_fixed_rotation(body,enable)

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

PARAMETERS

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

b2d.body.set_gravity_scale()

b2d.body.set_gravity_scale(body,scale)

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,damping)

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,velocity)

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_sleeping_allowed()

b2d.body.set_sleeping_allowed(body,enable)

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

PARAMETERS

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

b2d.body.set_transform()

b2d.body.set_transform(body,position,angle)

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,type)

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

PARAMETERS

body b2Body body
type b2BodyType the body type

Constants

b2d.body.B2_DYNAMIC_BODY

Dynamic body


b2d.body.B2_KINEMATIC_BODY

Kinematic body


b2d.body.B2_STATIC_BODY

Static (immovable) body