Skip to main content
Version: 0.12.0 (latest)

UePointerLockControls

The UePointerLockControls class provides a first-person shooter (FPS) style camera control system.
It uses the pointer lock API (via window_mouse_set_locked) to capture the mouse and allows looking around by moving the mouse, without the cursor hitting the edges of the screen.

Constructor​

new UePointerLockControls(camera, data = {})

Data parameters​

KeyTypeDefaultDescription
pointerSpeedXnumber0.1Horizontal mouse speed
pointerSpeedYnumber0.1Vertical mouse speed
minPolarAnglenumber0Camera pitch lower limit (radians)
maxPolarAnglenumberMath.PICamera pitch upper limit (radians)

Properties​

PropertyTypeDescription
cameraUeCameraThe controlled camera
pointerSpeedXnumberHorizontal mouse speed
pointerSpeedYnumberVertical mouse speed
minPolarAnglenumberCamera pitch lower limit. Range is [0, Math.PI] in radians
maxPolarAnglenumberCamera pitch upper limit. Range is [0, Math.PI] in radians
yawnumberCurrent horizontal rotation (degrees)
pitchnumberCurrent vertical rotation (degrees)
isLockedbooleanWhether the pointer is currently locked

🧩 Methods​

update()

Updates the camera direction based on mouse movement.
Must be called every frame.
Note: It handles the lock request automatically on a left-click, but only if the mouse is within the viewport (using global.UE_MOUSE validation).

lock()

Manually requests the pointer lock.

unlock()

Releases the pointer lock.

getDirection(target)

Returns a vector representing the current look direction.

  • target: An array [x, y, z] or struct {x, y, z} to store the result.
moveForward(distance)

Moves the camera position forward along the ground plane (based on yaw).

moveRight(distance)

Moves the camera position right relative to the current orientation.

🔔 Events​

EventDescription
changeFires when the user moves the mouse.
lockFires when the pointer lock status is "locked".
unlockFires when the pointer lock status is "unlocked".

🧠 Notes​

  • Input capture: The lock is requested on the first left-click inside the game view. Pressing Escape (default browser/engine behavior) will release the lock.
  • Orientation: The camera orientation is clamped according to minPolarAngle and maxPolarAngle. The default range is [0, Math.PI].
  • Direction: The controls update the camera.target property based on the calculated direction.
  • Inheritance: It inherits from UeControls, so it can be enabled/disabled via the enabled property.

Example​

// Initialize controls
const controls = new UePointerLockControls(camera, {
pointerSpeedX: 0.08,
pointerSpeedY: 0.08
});

// In your update loop
function update() {
controls.update();

// Example: move camera position using the control's methods
if (keyboard_check(ord("W"))) {
controls.moveForward(5);
}
}