logo

Babylon.js Market

By Lawrence

5 minutes

Every vehicle on this road so far is a soloist. Traffic arrives in its lane, hostiles come at you one at a time, the van sits still. Put three trucks in a line and drive them the obvious way — each one steers toward the one in front — and the line eats itself. Every follower aims at where the leader is, not where it went, so each takes a slightly tighter line than the truck ahead of it. By the second trailer the convoy is driving through the verge.

This road bends every 240 units. It will show.

Three vehicles, two components

Only the followers carry anything. Append the truck first:

"ConvoyTruck": {
  "tags": ["convoy"],
  "components": {
    "MeshPrimitive": {
      "primitive": "box",
      "width": 2.4,
      "height": 2.8,
      "depth": 7,
      "position": [-0.6, 1.4, 190],
      "material": {
        "diffuseColor": [0.42, 0.4, 0.36],
        "specularColor": [0.08, 0.08, 0.08]
      }
    },
    "Shadow": { "castShadow": true, "receiveShadow": false },
    "CarDrive": {
      "maxSpeed": 16,
      "acceleration": 5,
      "braking": 14,
      "steerRate": 1.4,
      "grip": 0.92,
      "keyboardControlled": false
    },
    "Health": { "hp": 12, "maxHp": 12 }
  }
}

Nothing on it knows it is a lead. It's an ordinary slow car with a lot of hit points.

Then the first trailer:

"ConvoyTrailer1": {
  "tags": ["convoy"],
  "components": {
    "MeshPrimitive": {
      "primitive": "box",
      "width": 2.4,
      "height": 2.6,
      "depth": 6.4,
      "position": [-0.9, 1.3, 182],
      "material": {
        "diffuseColor": [0.48, 0.45, 0.4],
        "specularColor": [0.08, 0.08, 0.08]
      }
    },
    "Shadow": { "castShadow": true, "receiveShadow": false },
    "TrafficConvoy": {
      "lead": "ConvoyTruck",
      "index": 0,
      "spacingSeconds": 0.85,
      "laneOffset": 0,
      "capacity": 360,
      "stringOut": true
    },
    "Health": { "hp": 8, "maxHp": 8 }
  }
}

ConvoyTrailer2 is the same block with position: [-1.2, 1.3, 174] and index: 1. Those authored positions matter for a frame or two and then stop mattering: after that the System owns each trailer's X, Z and yaw, and leaves its Y alone.

Note what the trailers do not have: a CarDrive. A follower isn't driving. It's being placed.

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