Edit: Looks like the problem is for touchpad not mouse.
Goal: To be able to respond to mouse movements even when key(s) is being pressed.
I want to modify PointerLockControls of Three.js so that: if user moves mouse when pressing W, then the camera should continue to move forward and the direction of camera should also change according to mouse movement. This is not happening in normal scenario. Here are the listeners:
Listener for mousemove event:
var onMouseMove = function ( event ) {
var movementX = event.movementX || event.mozMovementX || event.webkitMovementX || 0;
camera.rotation.y-=movementX*0.002;
};
Listener for keydown event:
var onKeyDown = function ( event ) {
case 38: // up
case 87: // w
moveForward = true;
break;
//keys: a, s, d are handled similarly
case 32: // space
if ( canJump === true ) velocity.y += 10;
canJump = false;
break;
}
Listener for keyup event:
var onKeyUp = function(event){
case 38: // up
case 87: // w
moveForward = false;
break;
}
I found that, if I hit spacebar when pressing W, then, the player continues to move forward AND responds to mouse movement. This is the effect I want (but it should work even without hitting spacebar).
Usually Operating Systems disable the touchpad when typing. You should find an option to toggle this somewhere on your OS settings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With