logo
By Lawrence

5 minutes

Launch the Ball

Four lessons in, the table is a photograph. Nice lighting, correct walls, a camera that frames itself — and not one moving pixel. Drop a sphere with a dynamic Havok body onto it right now and you'd get a fifth static object, because Havok's default gravity points at the floor and a pinball table is a ramp. The ball would land on the slab and stay there.

A pinball table only works if gravity leans. Everything that follows in this course — bumpers, spinners, saucers, the flippers you'll add next — assumes a ball that is always falling toward the bottom of the playfield. That lean, and the ball's whole life around it, belongs to one component.

Add the ball and the World entity

Two new entities. The ball, and a bare marker entity that carries the systems nothing else owns:

"Ball": {
  "tags": ["ball"],
  "components": {
    "MeshPrimitive": {
      "primitive": "sphere", "diameter": 0.84, "segments": 24,
      "position": [0, 0.5, -14],
      "material": { "diffuseColor": [0.95, 0.95, 1], "emissiveColor": [0.15, 0.15, 0.2] }
    },
    "Shadow": { "castShadow": true, "receiveShadow": false },
    "Physics": {
      "shapeType": "sphere", "motionType": "dynamic",
      "mass": 1, "restitution": 0.55, "friction": 0.02
    }
  }
},
"World": {
  "components": {
    "Plunger": {
      "ballTag": "ball",
      "spawnPosition": [0, 0.42, -14.5],
      "gravity": [0, -12, 14],
      "launchVelocityZ": 16,
      "launchJitterX": 2.5,
      "drainY": -3,
      "drainZMargin": 2,
      "triggerKey": "Space"
    }
  }
}

The ball carries no pinball component whatsoever. A sphere, a shadow, a dynamic body, and one tag. Everything that happens to it is done from a different entity, by a system that finds it with world.getEntitiesByTag('ball'). That one string is the entire coupling.

Continue reading

Unlock the Full Course

Every lesson, the runnable examples, and the finished build — yours to keep.

$9one-time

Was this page helpful?

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

↑↓ NavigateEnter SelectEsc CloseCtrl+K Open Search