logo
BlackHole

physics · physics-puzzle

BlackHole

2
Unlock

Install with the CLI:

bjs download BlackHole

BlackHole

A man-made black hole you pump up and let down with the mouse wheel.

What it does

BlackHole sits beside a GravityMass, which is the physics, and a MeshPrimitive sphere. It adds a mass dial, a horizon that follows the mass, and the look.

Every frame the System sets the GravityMass radius, the distance at which a rock is swallowed, to mass × horizonScale, and scales the sphere to match. What you see is what eats rocks. The radius grows linearly with mass, like a real horizon: at the defaults a hole of 600 has a radius of 1.32, and the dial runs from 0.33 at 150 to 3.3 at 1500.

A wheel notch over the hole moves its mass by massStep, heavier when you roll away from you. Gameplay takes the new radius at once. Only the sphere eases, over resizeSeconds, so a pumped hole swells instead of popping.

The look ships as an engine plugin: an accretion disk, white-hot at the inner edge and red at the rim, a halo with a photon ring, a glow while the pointer is over the hole or holding it, and a flare when it swallows a rock. The disk is tilted so it reads in a top view and a side view.

Setup

The engine work ships with the component, in adapter/register.ts. A project made with bjs create installs it for you: src/main.ts calls every adapter/register.ts that bjs download puts in the project, before the scene loads. If you boot the game from your own code, call it once, right after building the adapter:

TypeScript
import { registerBlackHoleExtension } from './Components/BlackHole/adapter/register';

const adapter = new BabylonAdapter();
registerBlackHoleExtension(adapter);
const game = new ArcadeGame(adapter, { … });

Without it the hole is a bare black sphere and the System warns once. The plugin is Babylon only. The horizon and the dial work the same without it.

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 BlackHole
    bjs download BlackHole

    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
{
  "Hole": {
    "tags": ["blackhole"],
    "components": {
      "MeshPrimitive": {
        "primitive": "sphere",
        "diameter": 1,
        "segments": 32,
        "material": { "diffuseColor": [0, 0, 0], "specularColor": [0, 0, 0], "emissiveColor": [0, 0, 0] }
      },
      "GravityMass": { "mass": 450, "absorbs": true, "softening": 0.3 },
      "BlackHole": { "diskInner": 1.8, "diskOuter": 5.2 },
      "PointerDrag": { "pickRadius": 2.6, "min": [-33, -14, -14], "max": [33, 14, 14] }
    }
  }
}

PointerDrag is optional: it brings the wheel and the glow. SpaceGolf puts all four on a Pool blueprint and hands holes out from it.

Props

  • minMass (number, default 150) — lightest the player may make it.
  • maxMass (number, default 1500) — heaviest. Never below minMass.
  • massStep (number, default 75) — mass added or removed per notch.
  • horizonScale (number, default 0.0022) — horizon radius per unit of mass.
  • resizeSeconds (number, default 0.25) — time the sphere takes to ease to a new size. 0 snaps.
  • diskInner (number, default 1.7) — inner edge of the disk, in horizon radii.
  • diskOuter (number, default 4.4) — outer edge of the disk, in horizon radii.
  • diskTilt (number, default 0.42) — tilt of the disk out of the horizontal, in radians.
  • hotColor (color, default [1, 0.86, 0.6]) — the disk's inner edge, and the photon ring.
  • coolColor (color, default [0.95, 0.32, 0.08]) — the disk's outer edge.
  • highlightColor (color, default [0.45, 0.85, 1]) — the hover and grab glow.
  • diskSpin (number, default 1.6) — disk speed at a mass of 600. It grows with the square root of the mass.

Events

Emits:

  • blackhole.mass.changed { entityId, mass, min, max } when a hole enters play, on every dial move, and when a mass written straight onto the GravityMass changes, as SpaceGolf's director does for each level.

Listens:

  • pointerdrag.wheel { entityId, delta } turns the dial by delta notches.
  • blackhole.mass.adjust { entityId, steps } turns it by steps, for buttons and touch screens.
  • pointerdrag.hover.changed, pointerdrag.started and pointerdrag.ended drive the glow.
  • gravity.body.contact sets off the flare when swallowed is true and massId is this hole.

Dependencies

  • MeshPrimitive: the sphere the System scales and the plugin dresses.
  • GravityMass: the mass and the swallow radius. A rock that touches the horizon is swallowed rather than crashed.

Notes

  • A radius set on the GravityMass in the scene is overwritten every frame. Size a hole with its mass and horizonScale.
  • The System sets absorbs and lenses on the GravityMass when the hole joins, so a scene can leave both out: the hole still swallows rocks and still bends a GravityLens sky.
  • Only setMeshScale is written, so it never races whoever drags the hole.
  • A parked hole is hidden, not undressed. Handed out again, it snaps to its new size and announces its mass again.
  • The disk and halo bloom only with a GlowLayer in the scene. The plugin keeps checking until one exists.

More like this

GravityBody
GravityMass
MeshPrimitive
PointerDrag
SpaceGolfHUD
AxisViewCamera
BoatMode
BoatWater
Bumper
CaptureZone
ContactDamage
ContactImpulse
DirectionalLight
EnvironmentTexture
Flash
GravityLens
HemisphericLight
LensFlare
MassDriver
Mesh
MotionTrail
MouseHole
NebulaSky
Obstacle
Physics
Renderable
RoadTreadmill
Shadow
ShipDamageFX
Skybox
SmokeScreen
SpaceDust
SpaceGolfDirector
SpaceRock
SpaceShooterFX
Spin
Spinner
SurfacePatch
ToneMapping
TrajectoryPreview
Velocity6DOF
WhiteHole
Wormhole

Was this page helpful?

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

↑↓ NavigateEnter SelectEsc CloseCtrl+K Open Search