Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy do FirstPersonControls.js stop functioning when another event listener is added?
    primarykey
    data
    text
    <p>I'm trying to write a 3d environment with FirstPersonControls.js for the movement and the following for the mouseclick listener:</p> <pre><code>function onDocumentMouseDown(event) { event.preventDefault(); var vector = new THREE.Vector3((event.clientX / window.innerWidth) * 2 - 1, -(event.clientY / window.innerHeight) * 2 + 1, 0.5); projector.unprojectVector(vector, camera); var raycaster = new THREE.Raycaster(camera.position, vector.sub(camera.position).normalize()); var intersects = raycaster.intersectObjects(adblocks); if (intersects.length &gt; 0) { intersects[0].object.material.color.setHex(Math.random() * 0xffffff); } } </code></pre> <p>and in init():</p> <pre><code>document.addEventListener('mousedown', onDocumentMouseDown, false); </code></pre> <p>I've done this on another document and it worked fine, however, this time I'm trying to include FirstPersonControls.js.</p> <p>In FirstPersonControls.js, I disabled the mousedown and mouseup listeners, by commenting out the listeners, like this:</p> <pre><code>//this.domElement.addEventListener( 'mousedown', bind( this, this.onMouseDown ), false ); //this.domElement.addEventListener( 'mouseup', bind( this, this.onMouseUp ), false ); </code></pre> <p>That worked fine. FirstPersonControls.js works fine by itself. However, when I add the extra listener for the MouseDown event, the key input (w, a, s, d, q, r, and f) stops responding. If I hold down a key immediately at page load, that key will work until I stop, then everything stops responding. Also, another thing I don't understand, and this may be related, which is why I'm mentioning it, is if I comment out this line in FirstPersonControls.js:</p> <pre><code>this.domElement.addEventListener( 'mousemove', bind( this, this.onMouseMove ), false ); </code></pre> <p>Nothing is changed. Everything keeps functioning exactly the same, which doesn't make sense to me, because I thought that's where the mousemovement event is binded to the document.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload