Fixed step simple physics library that works with circles. This library both works in browser and nodejs environments
Here is the example that demonstrates library.
https://ercang.github.io/simple-physics-js/examples/browser_example/
- Only circles are supported
- Static bodies can be defined using zero mass
- Collision layers are supported
- Bodies can be defined as "triggers"
- There is no rotation support
"./src" - Library source files
"./dist" - Minified library as a single file
"./examples" - Example usages of this library
"./third_party" - Third party code
// Create new simple physics instance
var physics = new SimplePhysics({
fixedStep: 15/1000,
linearDrag: 5,
gravity: new SimpleVector(0, 0),
size: 100
});
// initialize physics
physics.init();
// start loop by using animation frame
window.requestAnimationFrame(updateScreen);
function updateScreen()
{
// this will run a single fixed time step
physics.runStep();
window.requestAnimationFrame(updateScreen);
}
var obj = physics.createBody({
mass: 20,
radius: 5,
position: new SimpleVector(0, 0),
velocity: new SimpleVector(5, 0)
});
physics.removeAllBodies();
var bodies = physics.getBodyList();
var arrayLength = bodies.length;
for (var i = 0; i < arrayLength; i++)
{
var currentBody = bodies[i];
// get body position
var pos = currentBody.getPosition();
}
physics.registerCollisionListener({
onCollision: function(currentBody, otherBody, contactPoint){
}
});