const renderLayers = {
foreground: 1 << 0,
};
export const createPrismaticJointGame = async (): Promise<Game> => {
const { game, world, renderContext, time } = createGame('demo-game');
createCamera(world, {
isStatic: true,
cullingMask: renderLayers.foreground,
verticalWorldUnits: DEMO_VERTICAL_WORLD_UNITS,
});
await createSliders(world, renderContext, renderLayers.foreground);
const collisionPairs: CollisionPair[] = [];
const collisionManifolds: CollisionManifold[] = [];
const contactConstraints: ContactConstraint[] = [];
// Gravity and pumps must run before collision/joint resolution, so this
// tick's forces are reflected in the velocities those solvers see; the
// prismatic joint solver must run after collision resolution so each
// slider's rail constraint gets the "last word" on velocity each tick.
world.addSystem(createGravityEcsSystem(time));
world.addSystem(createPumpEcsSystem(time));
world.addSystem(createBroadPhaseEcsSystem(collisionPairs));
world.addSystem(
createNarrowPhaseEcsSystem(collisionPairs, collisionManifolds),
);
world.addSystem(
createCollisionResolutionEcsSystem(
collisionManifolds,
contactConstraints,
time,
),
);
world.addSystem(createPrismaticJointEcsSystem(time));
world.addSystem(createCameraEcsSystem(time));
world.addSystem(createRenderEcsSystem(renderContext));
world.addSystem(createEulerIntegrationEcsSystem(time));
return game;
};
This demo showcases PrismaticJoint in three different setups. On the left, a piston pumps back and forth along a level rail between two limits. In the middle, an elevator platform is pumped upward and falls back down under gravity to its lower limit. On the right, a ball is pumped back up a diagonal incline and rolls back down it under gravity. In every case the joint keeps the slider locked to its rail: no rotation, no drifting sideways off the line, only limited to translate along the axis. PrismaticJoint has no built-in motor, so each slider is driven by a small demo-only system that periodically applies an impulse (see pump.component.ts and pump.system.ts).