#

API Docs for: 0.6.1
Show: Inherited Protected Private Deprecated

# Body Class

Extends EventTarget
Defined in: `src/objects/Body.js:12`

Base class for all body types.

## Constructor

### `Body`

(

- `[options]`

)

Defined in `src/objects/Body.js:12`

#### Parameters:

- `[options]` Object optional
  - `[position]` Vec3 optional
  - `[velocity]` Vec3 optional
  - `[angularVelocity]` Vec3 optional
  - `[quaternion]` Quaternion optional
  - `[mass]` Number optional
  - `[material]` Material optional
  - `[type]` Number optional
  - `[linearDamping=0.01]` Number optional
  - `[angularDamping=0.01]` Number optional
  - `[allowSleep=true]` Boolean optional
  - `[sleepSpeedLimit=0.1]` Number optional
  - `[sleepTimeLimit=1]` Number optional
  - `[collisionFilterGroup=1]` Number optional
  - `[collisionFilterMask=1]` Number optional
  - `[fixedRotation=false]` Boolean optional
  - `[shape]` Body optional

#### Example:

    var body = new Body({
                mass: 1
            });
            var shape = new Sphere(1);
            body.addShape(shape);
            world.add(body);

- Index
- Methods
- Properties

## Item Index

### Methods

- addEventListener
- addShape
- applyForce
- applyImpulse
- applyLocalForce
- applyLocalImpulse
- computeAABB
- dispatchEvent
- getVelocityAtWorldPoint
- hasEventListener
- pointToLocalFrame
- pointToWorldFrame
- removeEventListener
- sleep
- sleepTick
- updateBoundingRadius
- updateInertiaWorld
- updateMassProperties
- updateSolveMassProperties
- vectorToLocalFrame
- vectorToWorldFrame
- wakeUp

### Properties

- aabb
- aabbNeedsUpdate
- allowSleep
- angularDamping
- angularVelocity
- AWAKE static
- collisionFilterGroup
- collisionFilterMask
- collisionResponse
- DYNAMIC static
- fixedRotation
- force
- inertia
- initAngularVelocity
- initPosition
- initQuaternion
- initVelocity
- invInertia
- invInertiaSolve
- invInertiaWorld
- invInertiaWorldSolve
- invMass
- KINEMATIC static
- linearDamping
- mass
- material
- position
- postStep deprecated
- preStep deprecated
- previousPosition
- quaternion
- shapeOffsets
- shapeOrientations
- shapes
- SLEEPING static
- sleepSpeedLimit
- sleepState
- sleepTimeLimit
- SLEEPY static
- STATIC static
- torque
- type
- velocity
- world

## Methods

### `addEventListener`

(

- `type`
- `listener`

)
EventTarget

Inherited from EventTarget: `src/utils/EventTarget.js:15`

Add an event listener

#### Parameters:

- `type` String
- `listener` Function

#### Returns:

EventTarget:

The self object, for chainability.

### `addShape`

(

- `shape`
- `offset`
- `quaternion`

)
Body

Defined in `src/objects/Body.js:507`

Add a shape to the body with a local offset and orientation.

#### Parameters:

- `shape` Shape
- `offset` Vec3
- `quaternion` Quaternion

#### Returns:

Body:

The body object, for chainability.

### `applyForce`

(

- `force`
- `worldPoint`

)

Defined in `src/objects/Body.js:637`

Apply force to a world point. This could for example be a point on the Body surface. Applying force this way will add to Body.force and Body.torque.

#### Parameters:

- `force` Vec3

  The amount of force to add.

- `worldPoint` Vec3

  A world point to apply the force on.

### `applyImpulse`

(

- `impulse`
- `worldPoint`

)

Defined in `src/objects/Body.js:688`

Apply impulse to a world point. This could for example be a point on the Body surface. An impulse is a force added to a body during a short period of time (impulse = force * time). Impulses will be added to Body.velocity and Body.angularVelocity.

#### Parameters:

- `impulse` Vec3

  The amount of impulse to add.

- `worldPoint` Vec3

  A world point to apply the force on.

### `applyLocalForce`

(

- `force`
- `localPoint`

)

Defined in `src/objects/Body.js:665`

Apply force to a local point in the body.

#### Parameters:

- `force` Vec3

  The force vector to apply, defined locally in the body frame.

- `localPoint` Vec3

  A local point in the body to apply the force on.

### `applyLocalImpulse`

(

- `force`
- `localPoint`

)

Defined in `src/objects/Body.js:729`

Apply locally-defined impulse to a local point in the body.

#### Parameters:

- `force` Vec3

  The force vector to apply, defined locally in the body frame.

- `localPoint` Vec3

  A local point in the body to apply the force on.

### `computeAABB`

()

Defined in `src/objects/Body.js:562`

Updates the .aabb

### `dispatchEvent`

(

- `event`

)
EventTarget

Inherited from EventTarget: `src/utils/EventTarget.js:68`

Emit an event.

#### Parameters:

- `event` Object
  - `type` String

#### Returns:

EventTarget:

The self object, for chainability.

### `getVelocityAtWorldPoint`

(

- `worldPoint`
- `result`

)
Vec3

Defined in `src/objects/Body.js:782`

Get world velocity of a point in the body.

#### Parameters:

- `worldPoint` Vec3
- `result` Vec3

#### Returns:

Vec3:

The result vector.

### `hasEventListener`

(

- `type`
- `listener`

)
Boolean

Inherited from EventTarget: `src/utils/EventTarget.js:34`

Check if an event listener is added

#### Parameters:

- `type` String
- `listener` Function

#### Returns:

Boolean:

### `pointToLocalFrame`

(

- `worldPoint`
- `result`

)
Vec3

Defined in `src/objects/Body.js:450`

Convert a world point to local body frame.

#### Parameters:

- `worldPoint` Vec3
- `result` Vec3

#### Returns:

Vec3:

### `pointToWorldFrame`

(

- `localPoint`
- `result`

)
Vec3

Defined in `src/objects/Body.js:477`

Convert a local body point to world frame.

#### Parameters:

- `localPoint` Vec3
- `result` Vec3

#### Returns:

Vec3:

### `removeEventListener`

(

- `type`
- `listener`

)
EventTarget

Inherited from EventTarget: `src/utils/EventTarget.js:50`

Remove an event listener

#### Parameters:

- `type` String
- `listener` Function

#### Returns:

EventTarget:

The self object, for chainability.

### `sleep`

()

Defined in `src/objects/Body.js:393`

Force body sleep

### `sleepTick`

(

- `time`

)

Defined in `src/objects/Body.js:411`

Called every timestep to update internal sleep timer and change sleep state if needed.

#### Parameters:

- `time` Number

  The world time in seconds

### `updateBoundingRadius`

()

Defined in `src/objects/Body.js:537`

Update the bounding radius of the body. Should be done if any of the shapes are changed.

### `updateInertiaWorld`

()

Defined in `src/objects/Body.js:608`

Update .inertiaWorld and .invInertiaWorld

### `updateMassProperties`

()

Defined in `src/objects/Body.js:754`

Should be called whenever you change the body shape or mass.

### `updateSolveMassProperties`

()

Defined in `src/objects/Body.js:434`

If the body is sleeping, it should be immovable / have infinite mass during solve. We solve it by having a separate "solve mass".

### `vectorToLocalFrame`

(

- `worldPoint`
- `result`

)
Vec3

Defined in `src/objects/Body.js:464`

Convert a world vector to local body frame.

#### Parameters:

- `worldPoint` Vec3
- `result` Vec3

#### Returns:

Vec3:

### `vectorToWorldFrame`

(

- `localVector`
- `result`

)
Vec3

Defined in `src/objects/Body.js:491`

Convert a local body point to world frame.

#### Parameters:

- `localVector` Vec3
- `result` Vec3

#### Returns:

Vec3:

### `wakeUp`

()

Defined in `src/objects/Body.js:381`

Wake the body up.

## Properties

### `aabb`

AABB

Defined in `src/objects/Body.js:308`

### `aabbNeedsUpdate`

Boolean

Defined in `src/objects/Body.js:314`

Indicates if the AABB needs to be updated before use.

### `allowSleep`

Boolean

Defined in `src/objects/Body.js:172`

If true, the body will automatically fall to sleep.

Default: true

### `angularDamping`

Number

Defined in `src/objects/Body.js:303`

### `angularVelocity`

Vec3

Defined in `src/objects/Body.js:231`

### `AWAKE`

Number static

Defined in `src/objects/Body.js:358`

### `collisionFilterGroup`

Number

Defined in `src/objects/Body.js:74`

### `collisionFilterMask`

Number

Defined in `src/objects/Body.js:79`

### `collisionResponse`

Number

Defined in `src/objects/Body.js:84`

Whether to produce contact forces when in contact with other bodies. Note that contacts will be generated, but they will be disabled.

### `DYNAMIC`

Number static

Defined in `src/objects/Body.js:332`

A dynamic body is fully simulated. Can be moved manually by the user, but normally they move according to forces. A dynamic body can collide with all body types. A dynamic body always has finite, non-zero mass.

### `fixedRotation`

Boolean

Defined in `src/objects/Body.js:296`

Set to true if you don't want the body to rotate. Make sure to run .updateMassProperties() after changing this.

Default: false

### `force`

Vec3

Defined in `src/objects/Body.js:128`

Linear force on the body

### `inertia`

Vec3

Defined in `src/objects/Body.js:268`

### `initAngularVelocity`

Vec3

Defined in `src/objects/Body.js:241`

### `initPosition`

Vec3

Defined in `src/objects/Body.js:105`

Initial position of the body

### `initQuaternion`

Quaternion

Defined in `src/objects/Body.js:225`

### `initVelocity`

Vec3

Defined in `src/objects/Body.js:122`

### `invInertia`

Vec3

Defined in `src/objects/Body.js:274`

### `invInertiaSolve`

Vec3

Defined in `src/objects/Body.js:286`

### `invInertiaWorld`

Mat3

Defined in `src/objects/Body.js:279`

### `invInertiaWorldSolve`

Mat3

Defined in `src/objects/Body.js:291`

### `invMass`

Number

Defined in `src/objects/Body.js:144`

### `KINEMATIC`

Number static

Defined in `src/objects/Body.js:348`

A kinematic body moves under simulation according to its velocity. They do not respond to forces. They can be moved manually, but normally a kinematic body is moved by setting its velocity. A kinematic body behaves as if it has infinite mass. Kinematic bodies do not collide with other static or kinematic bodies.

### `linearDamping`

Number

Defined in `src/objects/Body.js:156`

### `mass`

Number

Defined in `src/objects/Body.js:137`

Default: 0

### `material`

Material

Defined in `src/objects/Body.js:150`

### `position`

Vec3

Defined in `src/objects/Body.js:90`

### `postStep`

Function deprecated

Defined in `src/objects/Body.js:64`

Deprecated: Use World events instead

Callback function that is used AFTER stepping the system. Inside the function, "this" will refer to this Body object.

### `preStep`

Function deprecated

Defined in `src/objects/Body.js:56`

Deprecated: Use World events instead

Callback function that is used BEFORE stepping the system. Use it to apply forces, for example. Inside the function, "this" will refer to this Body object.

### `previousPosition`

Vec3

Defined in `src/objects/Body.js:100`

### `quaternion`

Quaternion

Defined in `src/objects/Body.js:214`

Orientation of the body

### `shapeOffsets`

Array

Defined in `src/objects/Body.js:256`

### `shapeOrientations`

Array

Defined in `src/objects/Body.js:262`

### `shapes`

Array

Defined in `src/objects/Body.js:250`

### `SLEEPING`

Number static

Defined in `src/objects/Body.js:372`

### `sleepSpeedLimit`

Number

Defined in `src/objects/Body.js:187`

If the speed (the norm of the velocity) is smaller than this value, the body is considered sleepy.

Default: 0.1

### `sleepState`

Number

Defined in `src/objects/Body.js:180`

Current sleep state.

### `sleepTimeLimit`

Number

Defined in `src/objects/Body.js:195`

If the body has been sleepy for this sleepTimeLimit seconds, it is considered sleeping.

Default: 1

### `SLEEPY`

Number static

Defined in `src/objects/Body.js:365`

### `STATIC`

Number static

Defined in `src/objects/Body.js:340`

A static body does not move during simulation and behaves as if it has infinite mass. Static bodies can be moved manually by setting the position of the body. The velocity of a static body is always zero. Static bodies do not collide with other static or kinematic bodies.

### `torque`

Vec3

Defined in `src/objects/Body.js:208`

Rotational force on the body, around center of mass

### `type`

Number

Defined in `src/objects/Body.js:162`

One of: Body.DYNAMIC, Body.STATIC and Body.KINEMATIC.

### `velocity`

Vec3

Defined in `src/objects/Body.js:112`

### `world`

World

Defined in `src/objects/Body.js:49`

Reference to the world the body is living in