Class b2Body

A rigid body.

Index

Properties

Methods

Properties

public static b2_dynamicBody: number

Dynamic Body

public static b2_kinematicBody: number

Kinematic Body

public static b2_staticBody: number

Static Body

Methods

public ApplyForce(force: b2Vec2, point: b2Vec2)

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

  • force: b2Vec2

    The world force vector, usually in Newtons (N).

  • point: b2Vec2

    The world position of the point of application.

public ApplyImpulse(impulse: b2Vec2, point: b2Vec2)

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

  • impulse: b2Vec2
  • point: b2Vec2

    The world position of the point of application.

public ApplyTorque(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

  • torque: number

    Force applied about the z-axis (out of the screen), usually in N-m.

public CreateFixture(def: b2FixtureDef): b2Fixture

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.

warning

This function is locked during callbacks.

Parameters

Returns

b2Fixture

The created fixture.

public CreateFixture2(shape: b2Shape, density?: number): b2Fixture

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. This function automatically updates the mass of the body.

warning

This function is locked during callbacks.

Parameters

  • shape: b2Shape

    The shaped of the fixture (to be cloned).

  • density?: number optional

    The shape density, default is 0.0, set to zero for static bodies.

Returns

b2Fixture

The created fixture.

public DestroyFixture(fixture: b2Fixture)

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

warning

This function is locked during callbacks.

Parameters

  • fixture: b2Fixture

    The fixed to be removed.

public GetAngle(): number

Get the angle in radians.

Returns

number

The current world rotation angle in radians

public GetAngularDamping(): number

Get the angular damping of the body.

Returns

number

Angular damping of the body.

public GetAngularVelocity(): number

Get the angular velocity.

Returns

number

The angular velocity in radians/second.

public GetContactList(): b2ContactEdge

Get the list of all contacts attached to this body.

Returns

b2ContactEdge

List of all contacts attached to this body.

public GetControllerList(): b2ControllerEdge

Get the list of all controllers attached to this body.

Returns

b2ControllerEdge

List of all controllers attached to this body.

public GetDefinition(): b2BodyDef

Get the definition containing the body properties.

note

This provides a feature specific to this port.

Returns

b2BodyDef

The body's definition.

public GetFixtureList(): b2Fixture

Get the list of all fixtures attached to this body.

Returns

b2Fixture

List of all fixtures attached to this body.

public GetInertia(): number

Get the central rotational inertia of the body.

Returns

number

The rotational inertia, usually in kg-m^2.

public GetJointList(): b2JointEdge

Get the list of all joints attached to this body.

Returns

b2JointEdge

List of all joints attached to this body.

public GetLinearDamping(): number

Get the linear damping of the body.

Returns

number

The linear damping of the body.

public GetLinearVelocity(): b2Vec2

Get the linear velocity of the center of mass.

Returns

b2Vec2

The linear velocity of the center of mass.

public GetLinearVelocityFromLocalPoint(localPoint: b2Vec2): b2Vec2

Get the world velocity of a local point.

Parameters

  • localPoint: b2Vec2

    Point in local coordinates.

Returns

b2Vec2

The world velocity of the point.

public GetLinearVelocityFromWorldPoint(worldPoint: b2Vec2): b2Vec2

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

Parameters

  • worldPoint: b2Vec2

    Point in world coordinates.

Returns

b2Vec2

The world velocity of the point.

public GetLocalCenter(): b2Vec2

Get the local position of the center of mass.

Returns

b2Vec2

Local position of the center of mass.

public GetLocalPoint(worldPoint: b2Vec2): b2Vec2

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

Parameters

  • worldPoint: b2Vec2

    Pointin world coordinates.

Returns

b2Vec2

The corresponding local point relative to the body's origin.

public GetLocalVector(worldVector: b2Vec2): b2Vec2

Gets a local vector given a world vector.

Parameters

  • worldVector: b2Vec2

    World vector.

Returns

b2Vec2

The corresponding local vector.

public GetMass(): number

Get the total mass of the body.

Returns

number

The body's mass, usually in kilograms (kg).

public GetMassData(data: b2MassData)

Get the mass data of the body. The rotational inertial is relative to the center of mass.

Parameters

  • data: b2MassData

    Body's mass data, this argument is out.

public GetNext(): b2Body

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

Returns

b2Body

Next body in the world's body list.

public GetPosition(): b2Vec2

Get the world body origin position.

Returns

b2Vec2

World position of the body's origin.

public GetTransform(): b2Transform

Get the body transform for the body's origin.

Returns

b2Transform

World transform of the body's origin.

public GetType(): number

Get the type of this body.

Returns

number

Body type as uint.

public GetUserData(): any

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

Returns

any

User's data, cast to the correct type.

public GetWorld(): b2World

Get the parent world of this body.

Returns

b2World

Body's world.

public GetWorldCenter(): b2Vec2

Get the world position of the center of mass.

Returns

b2Vec2

World position of the center of mass.

public GetWorldPoint(localPoint: b2Vec2): b2Vec2

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

Parameters

  • localPoint: b2Vec2

    Point on the body measured relative to the body's origin.

Returns

b2Vec2

localPoint expressed in world coordinates.

public GetWorldVector(localVector: b2Vec2): b2Vec2

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

Parameters

  • localVector: b2Vec2

    Vector fixed in the body.

Returns

b2Vec2

localVector expressed in world coordinates.

public IsActive(): boolean

Get the active state of the body.

Returns

boolean

True if the body is active, otherwise false.

public IsAwake(): boolean

Get the sleeping state of this body.

Returns

boolean

True if the body is awake, otherwise false.

public IsBullet(): boolean

Is the body treated like a bullet for continuous collision detection?

Returns

boolean

True if the body is treated like a bullet, otherwise false.

public IsFixedRotation(): boolean

Does this body have fixed rotation?

Returns

boolean

True for fixed, otherwise false.

public IsSleepingAllowed(): boolean

Is this body allowed to sleep?

Returns

boolean

True if the body can sleep, otherwise false.

public Merge(other: b2Body)

Merges another body into this. Only fixtures, mass and velocity are effected, Other properties are ignored.

note

This provides a feature specific to this port.

Parameters

public ResetMassData()

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 the mass and later you want to reset the mass.

public SetActive(flag: 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

  • flag: boolean

    True to activate, false to deactivate.

public SetAngle(angle: number)

Set the world body angle

Parameters

  • angle: number

    New angle of the body.

public SetAngularDamping(angularDamping: number)

Set the angular damping of the body.

Parameters

  • angularDamping: number

    New angular damping value.

public SetAngularVelocity(omega: number)

Set the angular velocity.

Parameters

  • omega: number

    New angular velocity in radians/second.

public SetAwake(flag: boolean)

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

Parameters

  • flag: boolean

    True to set the body to awake, false to put it to sleep.

public SetBullet(flag: boolean)

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

Parameters

  • flag: boolean

    True for bullet, false for normal.

public SetFixedRotation(fixed: boolean)

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

Parameters

  • fixed: boolean

    True for no rotation, false to allow for rotation.

public SetLinearDamping(linearDamping: number)

Set the linear damping of the body.

Parameters

  • linearDamping: number

    The new linear damping for this body.

public SetLinearVelocity(v: b2Vec2)

Set the linear velocity of the center of mass.

Parameters

  • v: b2Vec2

    New linear velocity of the center of mass.

public SetMassData(massData: b2MassData)

Set the mass properties to override the mass properties of the fixtures Note that this changes the center of mass position. Note that creating or destroying fixtures can also alter the mass. This function has no effect if the body isn't dynamic.

warning

The supplied rotational inertia should be relative to the center of mass.

Parameters

public SetPosition(position: b2Vec2)

Set the world body origin position.

Parameters

  • position: b2Vec2

    New world body origin position.

public SetPositionAndAngle(position: b2Vec2, angle: number)

Set the position of the body's origin and rotation (radians). This breaks any contacts and wakes the other bodies.

Parameters

  • position: b2Vec2

    New world body origin position.

  • angle: number

    New world rotation angle of the body in radians.

public SetSleepingAllowed(flag: boolean)

Is this body allowed to sleep

Parameters

  • flag: boolean

    True if the body can sleep, false if not.

public SetTransform(xf: b2Transform)

Set the position of the body's origin and rotation (radians). This breaks any contacts and wakes the other bodies. Note this is less efficient than the other overload - you should use that if the angle is available.

Parameters

  • xf: b2Transform

    Body's origin and rotation (radians).

public SetType(type: number)

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

Parameters

  • type: number

    Type enum.

public SetUserData(data: any)

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

Parameters

  • data: any

    The user data for this body.

public Split(callback: (fixture: Box2D.Dynamics.b2Fixture) => boolean): b2Body

Splits a body into two, preserving dynamic properties

note

This provides a feature specific to this port.

Parameters

  • callback: (fixture: Box2D.Dynamics.b2Fixture) => boolean

Returns

b2Body

The newly created bodies from the split.