Options
All
  • Public
  • Public/Protected
  • All
Menu

A rigid body.

Hierarchy

  • b2Body

Index

Constructors

constructor

Properties

Static b2_dynamicBody

b2_dynamicBody: number

Dynamic Body

Static b2_kinematicBody

b2_kinematicBody: number

Kinematic Body

Static b2_staticBody

b2_staticBody: number

Static Body

Methods

ApplyForce

  • 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.

    Returns void

ApplyImpulse

  • 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.

    Returns void

ApplyTorque

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

    • torque: number

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

    Returns void

CreateFixture

  • 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.

CreateFixture2

  • 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).

    • Optional density: number

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

    Returns b2Fixture

    The created fixture.

DestroyFixture

  • 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.

    Returns void

GetAngle

  • GetAngle(): number
  • Get the angle in radians.

    Returns number

    The current world rotation angle in radians

GetAngularDamping

  • GetAngularDamping(): number
  • Get the angular damping of the body.

    Returns number

    Angular damping of the body.

GetAngularVelocity

  • GetAngularVelocity(): number
  • Get the angular velocity.

    Returns number

    The angular velocity in radians/second.

GetContactList

  • Get the list of all contacts attached to this body.

    Returns b2ContactEdge

    List of all contacts attached to this body.

GetControllerList

  • Get the list of all controllers attached to this body.

    Returns b2ControllerEdge

    List of all controllers attached to this body.

GetDefinition

  • Get the definition containing the body properties.

    note

    This provides a feature specific to this port.

    Returns b2BodyDef

    The body's definition.

GetFixtureList

  • Get the list of all fixtures attached to this body.

    Returns b2Fixture

    List of all fixtures attached to this body.

GetInertia

  • GetInertia(): number
  • Get the central rotational inertia of the body.

    Returns number

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

GetJointList

  • Get the list of all joints attached to this body.

    Returns b2JointEdge

    List of all joints attached to this body.

GetLinearDamping

  • GetLinearDamping(): number
  • Get the linear damping of the body.

    Returns number

    The linear damping of the body.

GetLinearVelocity

  • Get the linear velocity of the center of mass.

    Returns b2Vec2

    The linear velocity of the center of mass.

GetLinearVelocityFromLocalPoint

  • 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.

GetLinearVelocityFromWorldPoint

  • 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.

GetLocalCenter

  • Get the local position of the center of mass.

    Returns b2Vec2

    Local position of the center of mass.

GetLocalPoint

  • 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.

GetLocalVector

  • Gets a local vector given a world vector.

    Parameters

    • worldVector: b2Vec2

      World vector.

    Returns b2Vec2

    The corresponding local vector.

GetMass

  • GetMass(): number
  • Get the total mass of the body.

    Returns number

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

GetMassData

  • 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.

    Returns void

GetNext

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

    Returns b2Body

    Next body in the world's body list.

GetPosition

  • Get the world body origin position.

    Returns b2Vec2

    World position of the body's origin.

GetTransform

  • Get the body transform for the body's origin.

    Returns b2Transform

    World transform of the body's origin.

GetType

  • GetType(): number
  • Get the type of this body.

    Returns number

    Body type as uint.

GetUserData

  • GetUserData(): any
  • Get the user data pointer that was provided in the body definition.

    Returns any

    User's data, cast to the correct type.

GetWorld

  • Get the parent world of this body.

    Returns b2World

    Body's world.

GetWorldCenter

  • Get the world position of the center of mass.

    Returns b2Vec2

    World position of the center of mass.

GetWorldPoint

  • 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.

GetWorldVector

  • 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.

IsActive

  • IsActive(): boolean
  • Get the active state of the body.

    Returns boolean

    True if the body is active, otherwise false.

IsAwake

  • IsAwake(): boolean
  • Get the sleeping state of this body.

    Returns boolean

    True if the body is awake, otherwise false.

IsBullet

  • 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.

IsFixedRotation

  • IsFixedRotation(): boolean
  • Does this body have fixed rotation?

    Returns boolean

    True for fixed, otherwise false.

IsSleepingAllowed

  • IsSleepingAllowed(): boolean
  • Is this body allowed to sleep?

    Returns boolean

    True if the body can sleep, otherwise false.

Merge

  • 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

    Returns void

ResetMassData

  • ResetMassData(): 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 the mass and later you want to reset the mass.

    Returns void

SetActive

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

    • flag: boolean

      True to activate, false to deactivate.

    Returns void

SetAngle

  • SetAngle(angle: number): void
  • Set the world body angle

    Parameters

    • angle: number

      New angle of the body.

    Returns void

SetAngularDamping

  • SetAngularDamping(angularDamping: number): void
  • Set the angular damping of the body.

    Parameters

    • angularDamping: number

      New angular damping value.

    Returns void

SetAngularVelocity

  • SetAngularVelocity(omega: number): void
  • Set the angular velocity.

    Parameters

    • omega: number

      New angular velocity in radians/second.

    Returns void

SetAwake

  • SetAwake(flag: boolean): void
  • 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.

    Returns void

SetBullet

  • SetBullet(flag: boolean): void
  • Should this body be treated like a bullet for continuous collision detection?

    Parameters

    • flag: boolean

      True for bullet, false for normal.

    Returns void

SetFixedRotation

  • SetFixedRotation(fixed: boolean): void
  • 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.

    Returns void

SetLinearDamping

  • SetLinearDamping(linearDamping: number): void
  • Set the linear damping of the body.

    Parameters

    • linearDamping: number

      The new linear damping for this body.

    Returns void

SetLinearVelocity

  • SetLinearVelocity(v: b2Vec2): void
  • Set the linear velocity of the center of mass.

    Parameters

    • v: b2Vec2

      New linear velocity of the center of mass.

    Returns void

SetMassData

  • 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

    Returns void

SetPosition

  • SetPosition(position: b2Vec2): void
  • Set the world body origin position.

    Parameters

    • position: b2Vec2

      New world body origin position.

    Returns void

SetPositionAndAngle

  • SetPositionAndAngle(position: b2Vec2, angle: number): void
  • 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.

    Returns void

SetSleepingAllowed

  • SetSleepingAllowed(flag: boolean): void
  • Is this body allowed to sleep

    Parameters

    • flag: boolean

      True if the body can sleep, false if not.

    Returns void

SetTransform

  • 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).

    Returns void

SetType

  • SetType(type: number): void
  • Set the type of this body. This may alter the mass and velocity

    Parameters

    • type: number

      Type enum.

    Returns void

SetUserData

  • SetUserData(data: any): void
  • Set the user data. Use this to store your application specific data.

    Parameters

    • data: any

      The user data for this body.

    Returns void

Split

  • Splits a body into two, preserving dynamic properties

    note

    This provides a feature specific to this port.

    Parameters

    Returns b2Body

    The newly created bodies from the split.

Generated using TypeDoc