How to avoid PointerLockControls error

You can store the time when the pointer lock was activated and then whenever you need to toggle it again you check if it was toggled/activated within the last 100 ms or so.

let pointerLockActivatedAt = null;

function inactivatePointerLock() {
    const now = performance.now()
    if (pointerLockActivatedAt != null && now - pointerLockActivatedAt < 100) {
        return
    }
    // do your thing
}
function activatePointerLock() {
    const now = performance.now()
    pointerLockActivatedAt = now
}
2 Likes