LittleJS 1.28.0

Box2D

LittleJS Box2D Physics Plugin

  • Box2dObject extends EngineObject with Box2D physics
  • Call box2dInit() to enable
  • You will also need to include box2d.wasm.js
  • Uses a super fast web assembly port of Box2D v2.3.1
  • More info: https://github.com/kripken/box2d.js
  • Functions to create polygon, circle, and edge shapes
  • Contact begin and end callbacks
  • Wraps b2Vec2 type to/from Vector2
  • Raycasting and querying
  • Box2dTileLayer for grid based collision
  • Every type of joint
  • Debug physics drawing
  • Box2D works per second: its velocities and accelerations are in units per second, and it reads the engine's gravity as units per second squared, where an EngineObject's are per frame

Classes

Functions

Members

Typedefs

Functions

box2dInit() → Promise<Box2dPlugin>asyncbox2d.js:2735

Box2d Init - Call with await to init box2d

await box2dInit();
box2dSetDebug(enable)box2d.js:305

Enable Box2D debug drawing

enable boolean

Members

Global Box2d Plugin object

box2dDebug : boolean default falsebox2d.js:31

Enable Box2D debug drawing

Typedefs

Box2dContact : Objectbox2d.js:50

Where and how hard two objects hit, given to beginContact

point Vector2|undefined

Where they touched in world space, between the two points of a flat landing, toward the one pushed harder; undefined for a sensor

normal Vector2|undefined

The other object's surface normal where they touched, pointing toward this object; undefined for a sensor

impulse number

An estimate of how hard they hit: the impulse that stops them closing, from the mass and inertia of both where they touched, times 1 + restitution; mass times world units per second, 0 for a sensor

Box2dPreSolveContact : Objectbox2d.js:120

A contact about to be solved, given to preSolve, whose changes the solver takes

point Vector2

Where they touch in world space, between the points when there are two

normal Vector2

The other object's surface normal where they touch, pointing toward this object

enabled boolean

Set false to let them pass through each other until they stop touching, true to make them collide again

friction number

The contact's friction, kept while they touch

restitution number

The contact's restitution, kept while they touch

surfaceSpeed number

How fast this object's surface moves there for this step, clockwise around it, its surfaceSpeed to start with