Fraxel includes a lightweight physics simulation system that handles gravity, velocity integration, force accumulation, impulses, and collision response. The system is built around theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/sanchedev/fraxel/llms.txt
Use this file to discover all available pages before exploring further.
RigidBody node — a sibling to a <collider> that registers itself with the singleton PhysicsSystem at startup. Each frame the physics system applies gravity, integrates velocity into position, and resolves collisions between registered bodies using separation and impulse-based response.
RigidBody Node
Add<rigid-body> as a sibling of a <collider> node inside a <transform> to enable physics on that object. The RigidBody node reads the sibling Collider at startup and registers both with the PhysicsSystem.
<rigid-body> must be a sibling of a <collider> inside the same <transform>. Without a sibling collider the physics body registers but has no shape to collide with.Props
| Prop | Type | Default | Description |
|---|---|---|---|
mass | number | 1 | Body mass. Higher values are heavier. 0 = infinite mass (static) |
friction | number | 0.1 | Friction coefficient (0–1). Applied to sliding on collision |
bounce | number | 0 | Restitution coefficient. 0 = no bounce, 1 = perfect bounce |
isStatic | boolean | false | If true, the body never moves regardless of forces |
useGravity | boolean | true | If false, gravity is not applied to this body |
Gravity
The default gravity is980 px/s² downward — equivalent to Earth gravity in pixel units. Change it at any time through the PhysicsSystem.gravity static setter:
PhysicsSystem is a singleton — gravity changes apply immediately to every non-static body in the scene.
Forces & Impulses
Access the underlyingPhysicsBody through rigidBodyNode.physicsBody. The physics body exposes three motion methods:
applyForce(force: Vector2)
Accumulates a force that is applied during the next physics integration step. Forces are expressed in pixels/second² and reset after each frame. Use for persistent effects such as thrust, wind, or buoyancy.
applyImpulse(impulse: Vector2)
Adds an instantaneous velocity change in pixels/second. The change is permanent until another force modifies the velocity. Use for jumps, explosions, or knockback.
setVelocity(v: Vector2)
Replaces the body’s velocity directly with the supplied value.
setVelocity
Use setVelocity when you want direct, authoritative control over movement — for example, capping a falling speed or matching a conveyor belt:
Static Bodies
SetisStatic (or mass={0}) on any rigid body that should never move — platforms, walls, and ground tiles are typical candidates. Static bodies still participate in collision resolution and push dynamic bodies away, but their own position is never changed by the physics solver.
Collision Response
When two registered physics bodies overlap,PhysicsSystem runs a three-step resolver each frame:
- Separation — both bodies are pushed apart along the collision normal, proportional to their inverse mass (lighter bodies move more).
- Impulse — a velocity impulse is applied to each body based on relative velocity and the
bouncecoefficient. Abounceof0absorbs all relative velocity;1reflects it perfectly. - Friction — lateral velocity is reduced by the
frictioncoefficient of both bodies to simulate sliding resistance.