logo
BilliardRack

gameplay · cue-sports

BilliardRack

Listens toKeyboardInput
1
Unlock

Install with the CLI:

bjs download BilliardRack

BilliardRack

Racks fifteen balls from a pool, and racks them again on R.

What it does

When its pool is ready, the rack takes fifteen balls from it and numbers them in 8-ball order: the 1 on the apex, the 8 in the middle of the third row, a solid and a stripe in the two back corners. It stops them, turns each so its number is on top, and lays them out in a tight triangle with the apex on the table's foot spot. Every ball touches its neighbours.

It also puts the cue ball (the BilliardBall numbered 0) back on the head spot.

Press R, or send billiards.rack.request, and it racks again. Balls still on the table go back to the pool first, and potted ones come back with them.

Use it in a scene

A scene is just data — a list of entities, each with its components. At startup the SceneLoader turns this JSON into a live world; edit the file and reload to rebuild it.

Build it from scratch with the bjs CLI:

  1. 1Scaffold a project
    npm create @babylonjsmarket/arcade@latest my-game

    World, renderer, and dev server — ready to run.

  2. 2Install dependencies
    cd my-game && npm install
  3. 3Add BilliardRack
    bjs download BilliardRack

    Copies its source into src/ so the scene resolves.

    First time? Run bjs login once.

  4. 4Paste the scene into src/scenes/arcade-room.ts and run
    npm run dev

    SceneLoader builds the world from the JSON; reload to rebuild.

JSON
{
  "Balls": {
    "tags": ["ball"],
    "components": {
      "Pool": { "name": "ball", "size": 15 },
      "MeshPrimitive": {
        "primitive": "sphere",
        "diameter": 0.05715,
        "segments": 32,
        "material": { "diffuseColor": [1, 1, 1], "specularColor": [0.55, 0.55, 0.55] }
      },
      "BilliardBall": { "number": 1 }
    }
  },
  "Rack": { "components": { "BilliardRack": { "pool": "ball" } } }
}

The Balls entity is the pool's blueprint. The rack numbers each ball as it takes it out.

Props

  • pool (string, default "ball"). The Pool to take balls from.
  • order (number[], default the 8-ball order). Ball numbers, apex first, then row by row from the top of the screen down.
  • gap (number, default 0). Extra space between neighbours, metres. 0 is a tight rack.
  • rackKey (string, default "KeyR"). The key that racks again.

Events

Emits:

  • billiards.rack.racked, { count }.

Listens to:

  • pool.ready, to rack the first time.
  • keyboard.keydown, for R.
  • billiards.rack.request, to rack again from a button or a game.

Dependencies

Notes

  • The rack only writes components. MeshPrimitive moves a pooled ball's mesh on the frame it comes out, and the table writes every mesh after that.
  • With no table it racks on a default 2.54 × 1.27 bed centred on the origin.
  • The cue ball leaves play and comes straight back when it is put on its spot, so its trail starts again there.

More like this

BilliardBall
BilliardTable
KeyboardInput
MeshPrimitive
AsteroidField
BallPossession
BallReset
BilliardCue
CaptureZone
ConicPath
Enemy
Goal
RespawnTimer
RoundReset
Scoreboard
SoccerDirector
SpaceGolfDirector
TrajectoryPreview
WaveDirector

Was this page helpful?

We read every note — tell us what's working and what isn't.

↑↓ NavigateEnter SelectEsc CloseCtrl+K Open Search