PhysicsWorld.ts

src/systems/PhysicsWorld.ts
import RAPIER from '@dimforge/rapier2d-compat';
/**
* Wraps a Rapier 2D physics world.
*
* Rapier is a Rust → WASM physics engine — deterministic, fast, and the
* modern choice for 2D and 3D web physics. We use the `-compat` build,
* which embeds the WASM in the JS bundle so there's no separate fetch.
*
* After construction, you MUST `await world.init()` before using it (the
* WASM module loads asynchronously). The Game class does this for you.
*
* Usage:
* const body = world.createDynamicBody(x, y);
* const collider = world.createBoxCollider(body, halfW, halfH);
* world.step();
* const { x, y } = body.translation();
*/
export class PhysicsWorld {
private world?: RAPIER.World;

Showing the first 20 lines.

Get full code

Support

Talk to the developers of this project to learn more

We have been building professional websites for big clients for over 15 years. Gallop templates and blocks is our best foundation for SEO websites and web apps.

© 2026 Web Plant Media, LLC