Options
All
  • Public
  • Public/Protected
  • All
Menu

A rigid body.

Hierarchy

  • b2Body

Index

Constructors

Properties

b2_dynamicBody: number

Dynamic Body

b2_kinematicBody: number

Kinematic Body

b2_staticBody: number

Static Body

Methods

  • 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

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

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

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

  • 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

    Returns void

  • GetAngle(): number
  • GetAngularDamping(): number
  • GetAngularVelocity(): number
  • Get the definition containing the body properties.

    note

    This provides a feature specific to this port.

    Returns b2BodyDef

    The body's definition.

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

    Returns number

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

  • GetLinearDamping(): number
  • 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.

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

  • GetMass(): number
  • 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

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

    Returns any

    User's data, cast to the correct type.

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

  • 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(): boolean
  • Get the active state of the body.

    Returns boolean

    True if the body is active, otherwise false.

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

    Returns boolean

    True if the body is awake, otherwise false.

  • 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(): boolean
  • IsSleepingAllowed(): boolean
  • 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(): 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(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(angle: number): void
  • SetAngularDamping(angularDamping: number): void
  • Set the angular damping of the body.

    Parameters

    • angularDamping: number

      New angular damping value.

    Returns void

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

    Parameters

    • omega: number

      New angular velocity in radians/second.

    Returns void

  • 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(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(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(linearDamping: number): void
  • Set the linear damping of the body.

    Parameters

    • linearDamping: number

      The new linear damping for this body.

    Returns void

  • 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

  • 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(position: b2Vec2): void
  • 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(flag: boolean): void
  • Is this body allowed to sleep

    Parameters

    • flag: boolean

      True if the body can sleep, false if not.

    Returns void

  • 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

    Returns void

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

  • 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