Skip to content

hemartin/physicsplain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

physicsplain – 2D physics in JavaScript

physicsplain is a simple 2D physics library written in JavaScript. The library is intended for small browser games and animations. physicsplain is lightweight in memory footprint and code size.

This library is heavily inspired by Erin Catto's GDC slides and Box2D. However, it does not provide all functionality that Box2D offers (see limitations below).

Examples

Below are a few examples as GIF animations. Check out the JavaScript examples.

Example 1

example1

Example 2

example2

Example 3

example3

Example 4

example4

Building the Minified Library

Install rollup:

  • npm install --save-dev rollup rollup-plugin-terser

Run rollup to create file target/physicsplain-min.js:

  • npx rollup -c rollup.config.js

Known Limitations

Currently only rectangles are supported as moving bodies. Rectangles, arcs, circles, and lines are supported as fixed bodies.

Sometimes the following issues occur:

  • Object collisions are not resolved properly, which results in objects moving into each other.
  • Inelastic collisions and constant forces (e.g., gravity) do not go well together, which also results in object moving into each other.

Consider using Box2D or other physics libraries if your project is impacted by these limitations.

Acknowledgments

This project was inspired by the following projects and websites:

About

2D physics in JavaScript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published