logo

Babylon.js Market

By Lawrence

5 minutes

The pitch is lit, but nothing can step onto it yet. There is no player. The keyboard controls nothing.

In this lesson, WASD will drive a capsule across the grass, and the camera will follow it. Four components do this 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. 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