Ever wondered, what impulse should I apply to the projectile so that it hits the target? This library will give you an answer. Ballistics is a WASM library that helps to calculate a proper velocity vector for projectiles.
The library is based on the wonderful magic of trajectory calculations by Forrest Smith. Check out his original post with the explanations.
Library features a low-level WASM binary and a high-level platform implementation.
- Written in AssemblyScript and compiled to WASM for high performance
- Features Playcanvas implementation, so it works with it out of the box
- Magically produces a correct impulse vector against both static and moving targets
- Download and place anywhere in your project the contents of
dist/pc-ballistics
folder. - Wait for
ballistics:ready
event, or check ifBallistics
is in the global scope. See this sample project for a simple setup.
You can find following API specs in this repository Wiki:
- Low level WASM binary API. You want this, if you are making your own implementation.
- High level Playcanvas implementation API. You want this, if you use this library with Playcanvas.
For production release:
$ gulp build
The tests are simple. Cubic, quartic and quadratic equations are tested against WolframAlpha results. Links to the test inputs are inside the comments of tests.
$ npm run test
MIT