Reference · Deterministic 2D physics
BodySpectype
What createBody is told. A dynamic body's mass and inertia are worked out from its shapes and density unless given.
Import it
import type { BodySpec } from "@johnmorrisdotca/karakuri/physics";
Definition
interface BodySpec {
id: string;
tag?: string;
type?: BodyType;
x?: number;
y?: number;
shapes: Shape[];
density?: number;
restitution?: number;
friction?: number;
fixedRotation?: boolean;
sensor?: boolean;
}
Members
| Name | Type | Description |
|---|---|---|
id | string | |
tag (optional) | string | undefined | |
type (optional) | BodyType | undefined | |
x (optional) | number | undefined | |
y (optional) | number | undefined | |
shapes | Shape[] | |
density (optional) | number | undefined | |
restitution (optional) | number | undefined | |
friction (optional) | number | undefined | |
fixedRotation (optional) | boolean | undefined | A body that does not turn (a character that stays upright). |
sensor (optional) | boolean | undefined |
Examples
import type { BodySpec } from "@johnmorrisdotca/karakuri/physics";
const spec: BodySpec={id:"ball",shapes:[{kind:"circle",x:0,y:0,r:3}],x:0,y:0};
const value: BodySpec = spec;
console.log(value);{
id: 'ball',
shapes: [ { kind: 'circle', x: 0, y: 0, r: 3 } ],
x: 0,
y: 0
}What it prints (run when this page was built)