@nanogram/ng-game-physics
v0.1.0
Published
Basic, renderer-agnostic physics + collision for Nanogram games — 2D and 3D alike.
Readme
ng-game-physics
Basic, renderer-agnostic physics + collision for Nanogram games — 2D and 3D alike.
- Use when: a game moves bodies under velocity/gravity or needs overlap/collision — the toolkit that replaces hand-rolled AABB overlap and clamp-to-play-area in the starters.
- Import:
@nanogram/ng-game-physics(dev dep / built ESM), or merged ontowindow.NGEnginein a scaffold. Dep:@nanogram/ng-game-core(for theVec2/Vec3TYPES only). - Interface doc: docs/physics.md
- Barrel:
src/index.ts
What's here
Pure math on core's {x,y}/{x,y,z} — no three, no pixi, no canvas. Four downward-only layers:
vec— non-mutating vector arithmetic (2D + 3D).body—Body2/Body3kinematics + semi-implicitintegrate*(takesdt).shapes— AABB (centre + half-extents), circle, sphere, bounds; constructors + min/max accessors.collide— overlap booleans + MTVhit*results, point-in-shape, ray/segment vs AABB.resolve—separate*,bounce*,friction*,clampToBounds*, andmoveAndCollide*(sweep vs a static AABB list).
Using it
Deterministic and dt-driven: integrate and resolve inside the template's rt.onFrame(dt => …) loop, at the engine's fixed timestep — never a second loop. Detection is pure; integrate*/separate*/clampToBounds*/moveAndCollide* mutate the objects you pass in.
