Box is a simple 2D physics engine written in JavaScript. It's primary focus is to be used in very simple games where only basic collisions features are needed, although it will probably get extend with advanced features in the future.
Highlights
- Low memory footprint with no objects being created at runtime
- Simple structure with commented code that's easy to grasp
- Provides a simple and direct way to access contact point information
- Runs in strict mode with sealed internal objects
Current Features
- AABB and Circle shapes
- Contact point information
- Angular/Velocity
- Static and Dynamic Friction
- Comes with a 2D Vector class
You can either use the pre-built version directly from the lib
folder or do a custom build:
$ npm install .
$ grunt
Auto generated API documentation is available here.
- Finalized public API
- Collision groups and layers
- OBB and Polygon shapes
- Additional contact point information
- Speed ups for huge scenes by applying spacial partioning
Setting up your World
The constant force applied to all objects is called gravity
and is defined as a Box.Vec2
.
var gravity = new Box.Vec2(0, 50);
The resolution of the simulation is determined by 2 values.
The first one is the number of steps
each call to World.update(dt)
will perform.
A step
is basically a full iteration over all objects and contacts.
The dt
delta time will be split by the number of steps
defined.
var steps = 10;
For example
dt
of20ms
with5 steps
will advance the simulation by4ms
on each step.
The second value that's responsible for the resolution is the number of iterations
.
If two bodies overlap, the will get separated by the engine.
Now as one can already imagine, this might lead to new overlaps with other bodies.
An increased number of iterations will therefore give more precise results and less visual overlap.
var iterations = 10;
Now you can create your Box.World
which will simply be empty and resting at first.
var world = new Box.World(gravity, steps, iterations);
Adding bodies
Coming soon.
Updating your world
Coming soon.
Rendering bodies
Coming soon.
Dealing with contacts
Coming soon.
Box is licenses under MIT.