When running the lock() functions, it seems to have no effect on the isLocked property, it remains false. Hence the mouseMove controls do not work.
I am running the lock function via a button click and it works as intended from the eventListeners below. I have tried using the selector property, and working straight from ‘three-stdlib’ but to no avail.
It works if I directly use the src at ‘three/examples/jsm/controls/’.
to be fixed
const PointerLock = () => {
const { camera, gl } = useThree();
useEffect(() => {
plControls.current.addEventListener('lock', () => (setShowMenu(false)));
plControls.current.addEventListener('unlock', () => (setShowMenu(true)));
}, [])
useFrame(() => {
// console.log(plControls.current.isLocked)
animate();
});
return <PointerLockControls ref={plControls} camera={camera} domElement={gl.domElement} />;
}
working code
import { PointerLockControls } from 'three/examples/jsm/controls/PointerLockControls'
extend({ PointerLockControls })
const PointerLock = () => {
const { camera, gl } = useThree();
useEffect(() => {
plControls.current.addEventListener('lock', () => (setShowMenu(false)));
plControls.current.addEventListener('unlock', () => (setShowMenu(true)));
}, [])
useFrame(() => {
// console.log(plControls.current.isLocked)
animate();
});
return <pointerLockControls ref={plControls} args={[camera, gl.domElement]} />;
}