Class: Body
Defined in: src/mobjects/physics/bodies.ts:77
A rigid body in the physics world.
The body is the single source of truth for its motion. An attached mobject follows the body, never the other way around.
Example
const ball = new Body({
position: [0, 3],
shape: { kind: 'circle', radius: 0.2 },
restitution: 0.8,
});
Constructors
Constructor
new Body(
options):Body
Defined in: src/mobjects/physics/bodies.ts:103
Parameters
options
BodyOptions = {}
Returns
Body
Properties
force
force:
Vec2
Defined in: src/mobjects/physics/bodies.ts:83
Force accumulator for the current step, cleared after integration.
gravityScale
readonlygravityScale:number
Defined in: src/mobjects/physics/bodies.ts:95
Per-body scale on the world gravity.
invMass
readonlyinvMass:number
Defined in: src/mobjects/physics/bodies.ts:87
Inverse mass. Zero for a static body, which disables all motion.
isStatic
readonlyisStatic:boolean
Defined in: src/mobjects/physics/bodies.ts:91
Whether the body is static (never moves).
mass
readonlymass:number
Defined in: src/mobjects/physics/bodies.ts:85
Mass in arbitrary units. A static body reports Infinity.
mobject
mobject:
Mobject
Defined in: src/mobjects/physics/bodies.ts:97
The attached mobject, or null.
position
position:
Vec2
Defined in: src/mobjects/physics/bodies.ts:79
Current position [x, y].
restitution
readonlyrestitution:number
Defined in: src/mobjects/physics/bodies.ts:89
Bounciness from 0 to 1.
shape
readonlyshape:BodyShape
Defined in: src/mobjects/physics/bodies.ts:93
The collision shape.
velocity
velocity:
Vec2
Defined in: src/mobjects/physics/bodies.ts:81
Current velocity [x, y] in units/sec.
z
readonlyz:number
Defined in: src/mobjects/physics/bodies.ts:99
The z of the attached mobject at attach time, kept on every move.
Accessors
radius
Get Signature
get radius():
number
Defined in: src/mobjects/physics/bodies.ts:134
The circle radius, or 0 for a polygon body.
Returns
number
Methods
aabb()
aabb(): [
number,number,number,number]
Defined in: src/mobjects/physics/bodies.ts:149
The axis-aligned bounds as [minX, minY, maxX, maxY] in world space.
A circle uses its radius; a polygon uses its vertex extent.
Returns
[number, number, number, number]
applyForce()
applyForce(
f):this
Defined in: src/mobjects/physics/bodies.ts:139
Add a force [x, y] to the accumulator for the current step.
Parameters
f
Returns
this
reset()
reset():
this
Defined in: src/mobjects/physics/bodies.ts:175
Restore the position and velocity recorded when the body was created.
Returns
this