logo
By Lawrence

5 minutes

Trail the Ship With a Chase Camera

You can fly, and flying takes you straight out of shot. The camera hasn't moved since Lesson 1: it sits at the origin watching the place the falcon used to be.

A driving game solves this by keeping the horizon level and the camera above and behind. There is no horizon here. Deep space gives a camera nothing to stay upright against — which turns out to change the code, not just the mood.

Add the chase camera block to the camera

Player gets a marker meaning follow me; Camera gets the settings for how to follow. Add "ChaseCameraTarget": {} to the player's components, and the chase block to the camera beside its CameraState6DOF:

"Camera": {
  "tags": ["camera"],
  "components": {
    "CameraState6DOF": { "fov": 1.05, "near": 0.1, "far": 200000 },
    "ChaseCamera6DOF": { "trailDistance": 18, "trailHeight": 6, "tau": 0.18 }
  }
}

Note what left the JSON as well as what arrived: the x, y, z and q you gave the camera in lesson 1 are gone. They were scaffolding for the five lessons that had no camera logic, and keeping them now would be worse than untidy — ChaseCamera6DOFSystem writes the same four fields every frame, so whatever you left there survives exactly one frame and then gets overwritten. Delete them. A number that is authored, read once, and then continuously replaced is a number that will lie to the next person who reads the scene.

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