Body Class
Base class for all body types.
Constructor
Body
-
[options]
Parameters:
-
[options]
Object optional-
[position]
Vec3 optional -
[mass]
Number optional -
[type]
Number optional -
[linearDamping]
Number optional
-
Example:
var body = new Body({
mass: 1
});
var shape = new Sphere(1);
body.addShape(shape);
world.add(body);
Item Index
Methods
Properties
- aabb
- aabbNeedsUpdate
- allowSleep
- angularDamping
- angularVelocity
- AWAKE static
- collisionFilterGroup
- collisionFilterMask
- collisionResponse
- DYNAMIC static
- DYNAMIC static
- DYNAMIC static
- fixedRotation
- float linearDamping
- force
- inertia
- initAngularVelocity
- initPosition
- initQuaternion
- initVelocity
- invInertia
- invInertiaSolve
- invInertiaWorld
- invInertiaWorldSolve
- invMass
- mass
- material
- position
- postStep deprecated
- preStep deprecated
- previousPosition
- quaternion
- shapeOffsets
- shapeOrientations
- shapes
- SLEEPING static
- sleepSpeedLimit
- sleepState
- sleepTimeLimit
- SLEEPY static
- type
- Vec3 tau
- velocity
- world
Methods
addEventListener
-
type
-
listener
Add an event listener
Parameters:
-
type
String -
listener
Function
Returns:
The self object, for chainability.
applyForce
-
force
-
worldPoint
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.tau.
applyImpulse
-
impulse
-
worldPoint
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.
computeAABB
()
Updates the .aabb
dispatchEvent
-
event
Emit an event.
Parameters:
-
event
Object-
type
String
-
Returns:
The self object, for chainability.
getVelocityAtWorldPoint
-
worldPoint
-
result
Get world velocity of a point in the body.
Returns:
The result vector.
hasEventListener
-
type
-
listener
Check if an event listener is added
Parameters:
-
type
String -
listener
Function
Returns:
pointToLocalFrame
-
worldPoint
-
result
Convert a world point to local body frame.
Returns:
pointToWorldFrame
-
worldPoint
-
result
Convert a local body point to world frame.
Returns:
pointToWorldFrame
-
worldPoint
-
result
Convert a local body point to world frame.
Returns:
removeEventListener
-
type
-
listener
Remove an event listener
Parameters:
-
type
String -
listener
Function
Returns:
The self object, for chainability.
sleep
()
Force body sleep
sleepTick
-
time
Called every timestep to update internal sleep timer and change sleep state if needed.
Parameters:
-
time
NumberThe world time in seconds
updateBoundingRadius
()
Update the bounding radius of the body. Should be done if any of the shapes are changed.
updateInertiaWorld
()
Update .inertiaWorld and .invInertiaWorld
updateMassProperties
()
Should be called whenever you change the body mass.
updateSolveMassProperties
()
If the body is sleeping, it should be immovable / have infinite mass during solve. We solve it by having a separate "solve mass".
wakeUp
()
Wake the body up.
Properties
aabbNeedsUpdate
Boolean
Indicates if the AABB needs to be updated before use.
allowSleep
Boolean
If true, the body will automatically fall to sleep.
angularDamping
Number
AWAKE
Number
static
collisionFilterGroup
Number
collisionFilterMask
Number
collisionResponse
Number
Whether to produce contact forces
DYNAMIC
Number
static
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.
DYNAMIC
Number
static
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.
DYNAMIC
Number
static
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.
fixedRotation
Boolean
Set to true if you don't want the body to rotate. Make sure to run .updateMassProperties() after changing this.
float linearDamping
Number
invMass
Number
mass
Number
postStep
Function
deprecated
Callback function that is used AFTER stepping the system. Inside the function, "this" will refer to this Body object.
preStep
Function
deprecated
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.
shapeOffsets
Array
shapeOrientations
Array
shapes
Array
SLEEPING
Number
static
sleepSpeedLimit
Number
If the speed (the norm of the velocity) is smaller than this value, the body is considered sleepy.
sleepState
Number
Current sleep state.
sleepTimeLimit
Number
If the body has been sleepy for this sleepTimeLimit seconds, it is considered sleeping.
SLEEPY
Number
static
type
Number
One of the states Body.DYNAMIC, Body.STATIC and Body.KINEMATIC
Vec3 tau
Unknown
Rotational force on the body, around center of mass