voxolith

makeLookController()

First-person look from mouse (pointer lock after a click, or drag without it), touch drag, the right stick and optional turn keys. Movement is gathered as events arrive and applied in update(dt), so stick and key speed is framerate-independent and the mouse is counted once.

function makeLookController(input: Input, opts?: LookOptions): LookController;

Defined in: engine/src/input/look.ts:80

Parameters

ParameterTypeDescription
inputInputThe surface's input. Touches on makeTouchControls controls never reach it.
opts?LookOptions-

Returns

LookController

The look state; feed yaw() and pitch() to the renderer's firstPersonFrame.

Example

const look = makeLookController(input, { pitch: -10, keys: { left: ["KeyQ"], right: ["KeyE"] } });
// per frame:
input.update();
look.update(dt);
const y = (look.yaw() * Math.PI) / 180;
const forward = [Math.sin(y), Math.cos(y)], right = [-Math.cos(y), Math.sin(y)];

On this page