PanTilt

Lets the user look around with the mouse or touch.

Free look-around. pan turns the camera left and right, tilt up and down, both in degrees. Each one is an InputAxis, so it can be driven by the mouse and touch through an input controller, or from code, for example in a cutscene.

To start facing a specific direction, pass a quaternion to the camera's initialState.

Settings

SettingDescriptionDefault
targetMakes pan and tilt relative to this target's rotation, for example a vehicle's cockpit. Omit for world space.
pan, tiltSettings for each axis, like range, wrap, damping or recentering. Later on, change them on aim.pan and aim.tilt.see Axes
autoNormalizeReact only. Keep pan inside its range after each drag while it wraps. autoNormalize on the axis elsewhere.false

Axes

AxisRangeCenterWraps
pan[-180, 180]0, facing forwardyes
tilt[-90, 90]0, levelno

Every axis starts at its center.

Usage

import { PanTiltAim } from '@pmndrs/klipp';
import { InputControllerDom } from '@pmndrs/klipp/dom';

const aim = new PanTiltAim(null, { tilt: { range: [-60, 60] } });
camera.aim = aim;

const look = { axes: { x: aim.pan, y: aim.tilt }, gain: 0.15 };
const controller = new InputControllerDom({
  mouseButtons: { left: look },
  touches: { one: look },
});
klipp.whileOnScreen(camera, () => {
  controller.connect(canvas);
  return () => controller.disconnect();
});
klipp.registerUpdate(() => controller.update()); // reads input before the cameras run

Pass a target to make pan and tilt relative to its rotation: new PanTiltAim(vehicle).

From code

aim.pan.applyDelta(5); // turn right by 5°
aim.pan.setValue(0);   // face forward at once
aim.tilt.value;        // current tilt

More in Input from data.