Follow

Keeps the camera at a fixed offset from a target.

Keeps the camera at offset from the target. By default the offset turns with the target, so a chase camera stays behind a character as it turns.

Settings

SettingDescriptionDefault
targetWhat to follow. See Targets.
offsetWhere the camera sits relative to the target.[0, 0, 10]
dampingSeconds to catch up with the target's position. 0 is instant. See Damping.0
rotationDampingSeconds to turn with the target, for every bindingMode but worldSpace. 0 is instant.0
maxSpeedMaximum catch-up speed, in units per second.Infinity
bindingModeHow the offset turns with the target. See below.'lockToTarget'

bindingMode

ModeThe offset turns with the target's
lockToTargetfull rotation, including roll.
lockToTargetNoRollyaw and pitch, but never rolls.
lockToTargetWithWorldUpyaw only. Good for flying or jumping targets.
lockToTargetOnAssignrotation at the moment target is set, the camera goes live or this mode is chosen, then stays fixed.
worldSpacenothing. The offset is always in world space.

A target without rotation, like a fixed point, always uses world space.

The binding mode also tells Aims like HardLookAt which way is up, so with lockToTarget the camera rolls along with the target, and with lockToTargetWithWorldUp it never does.

Usage

import { FollowBody, HardLookAtAim, targetPose } from '@pmndrs/klipp';

const player = targetPose.create(); // keep player.position and player.rotation up to date

camera.body = new FollowBody(player, { offset: [0, 3, 8], damping: 0.5 });
camera.aim = new HardLookAtAim(player);

Every binding mode but worldSpace turns the offset with the target, so fill in player.rotation and set player.hasRotation.

bindingMode

import { FollowBody, targetPose } from '@pmndrs/klipp';

const plane = targetPose.create(); // keep plane.position and plane.rotation up to date
camera.body = new FollowBody(plane, { offset: [0, 2, 10], bindingMode: 'lockToTargetWithWorldUp' });