https://github.com/villevli/physics2d-js
A small 2d physics demo calculating collisions and forces between polygons
https://github.com/villevli/physics2d-js
javascript physics-2d physics-simulation vanilla-javascript
Last synced: 11 months ago
JSON representation
A small 2d physics demo calculating collisions and forces between polygons
- Host: GitHub
- URL: https://github.com/villevli/physics2d-js
- Owner: villevli
- Created: 2025-03-03T15:52:42.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-03T17:49:33.000Z (over 1 year ago)
- Last Synced: 2025-04-04T12:34:26.648Z (over 1 year ago)
- Topics: javascript, physics-2d, physics-simulation, vanilla-javascript
- Language: JavaScript
- Homepage: https://villevli.github.io/physics2d-js/
- Size: 21.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
A small 2d physics demo calculating collisions and forces between polygons.
Implemented in JavaScript without libraries.
## Controls
- Click to give all objects an impulse towards the clicked point
- Press "c" to create a 5-gon at the cursor
- Press "w" to draw polygons without fill color
- Press "d" to draw the normal vector of all collisions with red
- Press "space" to pause the simulation and "s" to run one step
- Press "+" to lessen gravity
- Press "-" to increase gravity
## Known issues
- Friction not implemented
- Sometimes polygons can overlap presumably due to collision checks not working when the corners (vertices) of two polygons collide each other directly
- Sometimes when the browser is unfocused and focused again the existing polygons disappear. Did they fall outside the walls?