1681-engine / index / Body
Class: Body ​
Defined in: src/physics/Body.ts:11
A rigid body: plain data and a few helpers, no drawing. Positions are the shape's centre in world pixels, y down; velocities are px per second. Create bodies with PhysicsWorld.add, which also wakes them and puts them in the broad phase.
Constructors ​
Constructor ​
new Body(options): Body;Defined in: src/physics/Body.ts:86
Parameters ​
| Parameter | Type |
|---|---|
options | BodyOptions |
Returns ​
Body
Properties ​
angle ​
angle: number;Defined in: src/physics/Body.ts:23
Radians, clockwise on screen.
angularDamping ​
angularDamping: number;Defined in: src/physics/Body.ts:31
Turning lost per second, as a share.
angularVelocity ​
angularVelocity: number;Defined in: src/physics/Body.ts:27
Radians per second.
awake ​
awake: boolean = true;Defined in: src/physics/Body.ts:54
A sleeping body is not integrated and is treated as immovable until something wakes it.
friction ​
friction: number;Defined in: src/physics/Body.ts:43
fx ​
fx: number = 0;Defined in: src/physics/Body.ts:38
Force gathered for the next step (px·mass/s²), cleared after it.
fy ​
fy: number = 0;Defined in: src/physics/Body.ts:39
gravityScale ​
gravityScale: number;Defined in: src/physics/Body.ts:45
ground ​
ground: Body | null = null;Defined in: src/physics/Body.ts:60
What it stands on, while grounded.
grounded ​
grounded: boolean = false;Defined in: src/physics/Body.ts:58
Standing on something: a solid contact whose normal points up at this body (refreshed every step).
groundNx ​
groundNx: number = 0;Defined in: src/physics/Body.ts:61
groundNy ​
groundNy: number = 0;Defined in: src/physics/Body.ts:62
id ​
readonly id: number;Defined in: src/physics/Body.ts:12
inertia ​
readonly inertia: number;Defined in: src/physics/Body.ts:35
Moment of inertia about the centre (mass × px²); infinite for a body that does not rotate.
internalFaces ​
internalFaces: number = 0;Defined in: src/physics/Body.ts:51
Box faces lying against more solid ground (FACE_* bits): never a contact normal, so seams do not snag.
invInertia ​
readonly invInertia: number;Defined in: src/physics/Body.ts:36
invMass ​
readonly invMass: number;Defined in: src/physics/Body.ts:41
layer ​
layer: number;Defined in: src/physics/Body.ts:47
linearDamping ​
linearDamping: number;Defined in: src/physics/Body.ts:44
mask ​
mask: number;Defined in: src/physics/Body.ts:48
mass ​
readonly mass: number;Defined in: src/physics/Body.ts:40
maxX ​
maxX: number = 0;Defined in: src/physics/Body.ts:67
maxY ​
maxY: number = 0;Defined in: src/physics/Body.ts:68
minX ​
minX: number = 0;Defined in: src/physics/Body.ts:65
minY ​
minY: number = 0;Defined in: src/physics/Body.ts:66
prevAngle ​
prevAngle: number;Defined in: src/physics/Body.ts:25
Angle at the start of the last world step, for drawing between steps like prevX.
prevX ​
prevX: number;Defined in: src/physics/Body.ts:18
Position at the start of the last world step: draw at prev + (current - prev) × alpha.
prevY ​
prevY: number;Defined in: src/physics/Body.ts:19
restitution ​
restitution: number;Defined in: src/physics/Body.ts:42
restTime ​
restTime: number = 0;Defined in: src/physics/Body.ts:56
Seconds spent below the world's sleep speed.
rotates ​
readonly rotates: boolean;Defined in: src/physics/Body.ts:29
Contacts and torques turn it (BodyOptions.rotates).
sensor ​
readonly sensor: boolean;Defined in: src/physics/Body.ts:46
shape ​
shape: Shape;Defined in: src/physics/Body.ts:14
sin ​
sin: number = 0;Defined in: src/physics/Body.ts:72
torque ​
torque: number = 0;Defined in: src/physics/Body.ts:33
Torque gathered for the next step, cleared after it.
type ​
readonly type: BodyType;Defined in: src/physics/Body.ts:13
userData ​
userData: unknown;Defined in: src/physics/Body.ts:49
vx ​
vx: number;Defined in: src/physics/Body.ts:20
vy ​
vy: number;Defined in: src/physics/Body.ts:21
wnx ​
readonly wnx: Float64Array<ArrayBuffer>;Defined in: src/physics/Body.ts:76
wny ​
readonly wny: Float64Array<ArrayBuffer>;Defined in: src/physics/Body.ts:77
wy ​
readonly wy: Float64Array<ArrayBuffer>;Defined in: src/physics/Body.ts:75
x ​
x: number;Defined in: src/physics/Body.ts:15
y ​
y: number;Defined in: src/physics/Body.ts:16
Accessors ​
axisAligned ​
Get Signature ​
get axisAligned(): boolean;Defined in: src/physics/Body.ts:150
A box at no angle: the cheap axis-aligned tests apply to it.
Returns ​
boolean
isDynamic ​
Get Signature ​
get isDynamic(): boolean;Defined in: src/physics/Body.ts:115
Returns ​
boolean
isStatic ​
Get Signature ​
get isStatic(): boolean;Defined in: src/physics/Body.ts:119
Returns ​
boolean
maxExtent ​
Get Signature ​
get maxExtent(): number;Defined in: src/physics/Body.ts:142
The furthest the shape reaches from the centre: how far a corner sweeps as the body turns.
Returns ​
number
minHalfExtent ​
Get Signature ​
get minHalfExtent(): number;Defined in: src/physics/Body.ts:134
The smallest half size of the shape: how far it may move in one sub-step without passing through anything.
Returns ​
number
moving ​
Get Signature ​
get moving(): boolean;Defined in: src/physics/Body.ts:124
Moves by itself this step: an awake dynamic body or any kinematic one.
Returns ​
boolean
solverInvMass ​
Get Signature ​
get solverInvMass(): number;Defined in: src/physics/Body.ts:129
Inverse mass as the solver sees it: a sleeping body holds still like ground.
Returns ​
number
Methods ​
applyAngularImpulse() ​
applyAngularImpulse(impulse): void;Defined in: src/physics/Body.ts:279
An instant change of spin: angular velocity changes by impulse / inertia.
Parameters ​
| Parameter | Type |
|---|---|
impulse | number |
Returns ​
void
applyForce() ​
applyForce(
fx,
fy,
px?,
py?
): void;Defined in: src/physics/Body.ts:263
A force held for the next step (thrust, wind); it is cleared once the step has used it. At a world point, it also turns the body.
Parameters ​
| Parameter | Type |
|---|---|
fx | number |
fy | number |
px? | number |
py? | number |
Returns ​
void
applyImpulse() ​
applyImpulse(
ix,
iy,
px?,
py?
): void;Defined in: src/physics/Body.ts:254
An instant change of momentum (a jump, a hit): velocity changes by impulse / mass. Given a world point (px, py) off the centre, a body that rotates is also set turning.
Parameters ​
| Parameter | Type |
|---|---|
ix | number |
iy | number |
px? | number |
py? | number |
Returns ​
void
applyTorque() ​
applyTorque(torque): void;Defined in: src/physics/Body.ts:272
A turning force held for the next step (mass × px² / s², clockwise on screen when positive).
Parameters ​
| Parameter | Type |
|---|---|
torque | number |
Returns ​
void
setAngle() ​
setAngle(angle): void;Defined in: src/physics/Body.ts:310
Turns the body to angle without sweeping it there (like setPosition).
Parameters ​
| Parameter | Type |
|---|---|
angle | number |
Returns ​
void
setAngularVelocity() ​
setAngularVelocity(w): void;Defined in: src/physics/Body.ts:286
Sets the spin (a kinematic body turns at it; a dynamic one that rotates starts at it).
Parameters ​
| Parameter | Type |
|---|---|
w | number |
Returns ​
void
setPosition() ​
setPosition(
x,
y,
angle?
): void;Defined in: src/physics/Body.ts:301
Puts the body somewhere without sweeping it there; the drawn position jumps too (no interpolation across it). A static body moved this way must be followed by PhysicsWorld.staticsChanged().
Parameters ​
| Parameter | Type |
|---|---|
x | number |
y | number |
angle | number |
Returns ​
void
setVelocity() ​
setVelocity(vx, vy): void;Defined in: src/physics/Body.ts:244
Parameters ​
| Parameter | Type |
|---|---|
vx | number |
vy | number |
Returns ​
void
toLocal() ​
toLocal(px, py): object;Defined in: src/physics/Body.ts:315
A world point in the body's own frame (before its turn).
Parameters ​
| Parameter | Type |
|---|---|
px | number |
py | number |
Returns ​
object
x ​
x: number;y ​
y: number;toWorld() ​
toWorld(lx, ly): object;Defined in: src/physics/Body.ts:322
A point of the body's own frame in the world.
Parameters ​
| Parameter | Type |
|---|---|
lx | number |
ly | number |
Returns ​
object
x ​
x: number;y ​
y: number;updateBounds() ​
updateBounds(): void;Defined in: src/physics/Body.ts:154
Returns ​
void
velocityAt() ​
velocityAt(px, py): object;Defined in: src/physics/Body.ts:292
Velocity of the body's material at a world point: its own plus what its spin adds there.
Parameters ​
| Parameter | Type |
|---|---|
px | number |
py | number |
Returns ​
object
x ​
x: number;y ​
y: number;wake() ​
wake(): void;Defined in: src/physics/Body.ts:238
Returns ​
void