logo
By Lawrence

5 minutes

Make Bullets Hit the Ship

Your tracers pour off the nose and fly right through your target. The round doesn't know the ship is there. The ship doesn't know it got hit. To make a shot land, you need two parts that work in the same coordinate frame. One is a target that knows its own shape. The other is a test that can catch a round moving 480 units a second. And the ship may be rolling at the moment you hit it.

Add a target to shoot at

You need something to shoot at. Add a still practice target to the running scene. It's a bronze kilrathi hulk, parked off to your right:

"Enemy1": {
  "tags": ["enemy"],
  "components": {
    "Transform6DOF": { "x": 26, "y": 6, "z": 62, "rx": 0, "ry": 0, "rz": 0 },
    "Renderable": {
      "shape": "kilrathi",
      "sx": 3, "sy": 1, "sz": 4,
      "r": 0.62, "g": 0.45, "b": 0.32,
      "emissive": 0.15,
      "glbSrc": "/spaceshooter/bronzeship.glb"
    },
    "Parts": {
      "defs": [
        { "name": "leftWing",  "cx": -1.4, "cy": -0.05, "cz": -1.3, "hx": 0.85, "hy": 0.15, "hz": 0.85, "maxHp": 2, "critical": false, "meshSuffixes": ["-lwing"] },
        { "name": "rightWing", "cx":  1.4, "cy": -0.05, "cz": -1.3, "hx": 0.85, "hy": 0.15, "hz": 0.85, "maxHp": 2, "critical": false, "meshSuffixes": ["-rwing"] }
      ]
    },
    "SpaceShooterHealth": { "hp": 4, "maxHp": 4 }
  }
}

That Parts block is the slow way to do this, on purpose: you type two axis-aligned boxes by hand, straight into JSON, each sitting in the ship's own local space. Lesson 3 makes that chore go away. Both boxes are critical: false, so rounds still register and parts still shed, but this hulk can't die yet — blowing a ship apart is Lesson 4. (The Player already has MachineGun from Lesson 1, so it can fire.)

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