physics-engine
Physics engine that I made with the stuff we learned in school
Used lots of trig functions and "Newton"s equations
Importing
Just add this to your HTML to import it!
<script src="https://unpkg.com/physics-engine"></script>
Example
Add a canvas to your body, so you can use it for rendering
<body>
<canvas></canvas>
</body>
Initializing physics engine
<script>
window.Phygic.then(Phygic => {
// your code goes here!
console.log("Phygic has been loaded! ", Phygic);
});
</script>
Getting canvas
const canvas = document.querySelector("canvas");
Creating a physics world
Note: If you don't want the renderer you don't have to enter the canvas element
const world = new Phygic.World(canvas);
Rendering
world.createAnimators();
Adding camera movement, tile dragging etc.
world.addHelpers();
Adding a box
new Phygic.Tile(50, 0, world);
Adding a static tile so our box doesn't fall to the nothingness
new Phygic.Tile(50, 500, {world, isStatic: true});
Final product:
<body>
<canvas></canvas>
</body>
<script src="https://unpkg.com/physics-engine"></script>
<script>
window.Phygic.then(Phygic => {
const canvas = document.querySelector("canvas");
const world = new Phygic.World(canvas);
world.createAnimators();
world.addHelpers();
new Phygic.Tile(50, 0, world);
new Phygic.Tile(50, 500, {world, isStatic: true});
});
</script>