5.4.0

PointerLock Controls

Allows you to capture the mouse movement and simulate a first person camera

PointerLockControls is a camera controller that allows you to capture the mouse movement and simulate a first person camera. It is a perfect choice for first person 3D games.

This control uses the Pointer Lock API, the same rules are applied, for example, you need to interact with the browser to "lock" or start the event. In addition, you need to wait 1 second between canceling and re-starting the event

Usage

<script setup lang="ts">
import { TresCanvas } from '@tresjs/core'
import { PointerLockControls, Box } from '@tresjs/cientos'
</script>

<template>
  <TresCanvas>
    <TresPerspectiveCamera />
    <Box :position-y="0.5" />
    <PointerLockControls />
    <TresGridHelper />
  </TresCanvas>
</template>
Is really important that the Perspective camera is set first in the canvas. Otherwise might break.

Props

PropDescriptionDefault
makeDefaultIf true, the controls will be set as the default controls for the scene.false
cameraThe camera to control.undefined
domElementThe dom element to listen to.undefined
selectorAccept an id element as string, if it is set, the new element will be used as the triggerundefined

Events

<PointerLockControls @change="onChange" @is-lock="(state) => isActive(state)" />
EventDescription
isLockReturn true if "lock", false if "unlock" events are trigger.
changeDispatched when the control changes.