logo
By Lawrence

5 minutes

Drive Your Player

The pitch is lit, but nothing can step onto it yet: there is no player, and the keyboard controls nothing.

WASD will drive a capsule across the grass with the camera following. Four components do that work and none of them knows about the others — the keys turn into named intents, a bridge turns those into a move vector, a mover walks the capsule, and the camera follows. Each one talks only over the bus.

Add the player to the scene

Add one entity, tagged player. It carries the whole chain, from input to camera:

src/scenes/soccer.json
"Player": {
  "tags": ["player"],
  "components": {
    "MeshPrimitive": {
      "primitive": "capsule", "radius": 0.5, "height": 2, "position": [-4, 1, 0],
      "material": { "diffuseColor": [0.95, 0.45, 0.45], "emissiveColor": [0.25, 0.05, 0.05] }
    },
    "Shadow": { "castShadow": true, "receiveShadow": false },
    "PlayerInput": {},
    "Movement": { "speed": 7, "groundY": 0 },
    "PlayerInputBridge": { "jumpActions": ["jump"], "invertX": true },
    "CameraFollow": { "target": "Player", "smoothing": 4, "offsetY": 1.0 }
  }
}

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